python 装饰器体验,python装饰体验,from time im
from time import ctime,sleepdef tsfunc(fun): def weappedFunc(*args,**kwargs): print(ctime(),fun.__name__,"called") return fun(*args,**kwargs) return weappedFuncdef tsfunc2(arg): def weappendFunc(fun): def weappendFunc2(*args,**kwargs): print(ctime(),fun.__name__,"called",arg) fun(*args,**kwargs) return weappendFunc2 return weappendFunc@tsfuncdef foo(a,b): print("foo calling:","a=",a,"b=",b) pass@tsfuncdef foo2(a,b,c): print("foo2 calling:","a=",a,"b=",b,"c=",c)@tsfuncdef foo3(): print("foo3 called")@tsfunc2("hehhe")def foo4(): print("foo4 called")foo(1,2)foo2(1,2,3)foo3()foo4()#该片段来自于http://byrx.net
评论关闭