#python闭包打印日志功能
def log_wraper(func):
def inner():
start_time = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
func()
end_time = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
print("logging: func:{} runs from {} to {}".format(func.__name__,start_time,end_time))
return inner
复制代码
#斐波那契额数列--yield语句
def fib_yield_for():
a,b = 0,1
for _ in range(10):
a,b = b,a+b
print(a,end=' ')
if **name** == '**main**':
myfun = log_wraper(fib_yield_for)
myfun()