首页 > 其他 > 详细

装饰器参数

时间:2019-10-24 21:00:10      阅读:71      评论:0      收藏:0      [点我收藏+]
#有多个函数,需要计算他们的执行时间
import time

def show_time(f):
def inner(*x,**y):
starttime = time.time()
f(*x,**y)
endtime = time.time()
print("执行时间:%s"%(endtime - starttime))
return inner

@show_time #foo = show_time(foo) @show_time同等与foo = show_time(foo)

def foo(*a,**b):
fnum = 0
for i in a:
fnum += i
print(fnum)
print("this is foo")
time.sleep(2)
#foo = show_time(foo)
foo(1,2,3,4,5,6)

装饰器参数

原文:https://www.cnblogs.com/TKOPython/p/11734539.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!