import time

def DecoUserPrint(UserFunc):#定义一个DecoUserPrint接收参数的多重方法

def DecoPrint():

StartTime = time.time()

UserFunc()#执行DecoPrint接收的方法

OverTime = time.time()

print(OverTime-StartTime)

return DecoPrint

@DecoUserPrint#为下方的,方法调用装饰器,UserPrint = DecoUserPrint(UserPrint)

def UserPrint():

time.sleep(1)

print("egon")

UserPrint()#执行被修饰的UserPrint方法

 

查看原文