# -*- coding: utf-8 -*-
from time import ctime
from time import sleep
def ftfunc(func):
def timef():
print "[%s] %s() called" % (ctime(),func.__name__)
return func
return timef
@ftfunc
def foo():
print 'hello'
if __name__ == '__main__':
foo()()
sleep(2)
for i in range(2):
sleep(1)
foo()()
此代码运行结果:

其实还可以分别对返回的timef函数加上括号,看看结果会是怎么样的。可以更好理解python中函数的概念。