import time
def logger(flag):
def show_time(f): #装饰器函数
def inner(*x,**y): #闭包函数
stat = time.time()
f(*x,**y)
end = time.time()
print('spend %s' % (end - stat))
if flag == 'true':
print('日志记录')
return inner
return show_time
@logger('true') #show_time
#@show_time #foo = show_time(foo)
def foo(*a,**b):
sums = 0
for i in a:
sums += i
print(sums)
time.sleep(1)
foo(1,2,3,4)