python(5)函数装饰器

这个还真的没怎么看懂,先上代码,此代码即为函数装饰器的一种用法。回头再来看一遍。

#!/usr/bin/env python
 
from time import ctime, sleep
 
def tsfunc(func):
    def wrappedFunc():
        print '[%s] %s() called' % (
            ctime(), func.__name__)
        return func()
    return wrappedFunc
 
@tsfunc
def foo():
    pass
 
 
foo()
sleep(4)
 
for i in range(2):
    sleep(1)
    foo()
原文地址:https://www.cnblogs.com/luhouxiang/p/2432444.html