import time def wrapper(type): print('start------',type) def outter(fun): def inner(*args,**kwargs): start_time = time.time() fun(*args,**kwargs) end_time=time.time() print('run time %d'%(end_time-start_time)) return 'ret' print('------end') return inner return outter @wrapper(type='3333') def fun1(name,age): time.sleep(3) print('fun1 run',name,age) #fun1=wrapper(fun1) #fun1('howhy',34)#被装饰的函数带参数@wrapper() #fun1=wrapper('aaa1')(fun1)#装饰器带参数@wrapper(type='3333') ret=fun1('aaa4',34)#被装饰的函数返回值 print(ret)
标签:fun1,python,wrapper,time,print,type,装饰,def From: https://www.cnblogs.com/howhy/p/17869114.html