函数调用,装饰器

来源:互联网 发布:mysql 按某字段排序 编辑:程序博客网 时间:2024/05/20 07:37

代码块1:
from time import ctime,sleep
def tsfun(func):
def two():
print ‘[%s] %s() called’ %(ctime(),func.name)
return func()
return two

@tsfun
def foo():
print ‘ok’
pass
foo()
sleep(1)

for i in range(2):
sleep(1)
foo()

代码块2:
from time import ctime,sleep
def tsfun():
def two():
print ‘[%s] called’ %(ctime())
return tsfun
return two()

tsfun()

如何理解1,2中return two(),与return two。到底什么时候该返回什么。求解释

0 0