- from time import ctime,sleep
- def tsfunc(fun):
- def weappedFunc(*args,**kwargs):
- print(ctime(),fun.__name__,"called")
- return fun(*args,**kwargs)
- return weappedFunc
- def tsfunc2(arg):
- def weappendFunc(fun):
- def weappendFunc2(*args,**kwargs):
- print(ctime(),fun.__name__,"called",arg)
- fun(*args,**kwargs)
- return weappendFunc2
- return weappendFunc
- @tsfunc
- def foo(a,b):
- print("foo calling:","a=",a,"b=",b)
- pass
- @tsfunc
- def foo2(a,b,c):
- print("foo2 calling:","a=",a,"b=",b,"c=",c)
- @tsfunc
- def foo3():
- print("foo3 called")
- @tsfunc2("hehhe")
- def foo4():
- print("foo4 called")
- foo(1,2)
- foo2(1,2,3)
- foo3()
- foo4()
- #该片段来自于http://www.codesnippet.cn/detail/151120137214.html
来源: http://www.codesnippet.cn/detail/151120137214.html