首页 > 其他 > 详细

修饰器练习

时间:2018-08-05 16:12:47      阅读:112      评论:0      收藏:0      [点我收藏+]
import time
# def foo():
# print("in the foo")
# bar()
# #foo()
# def bar():
# print("in the bar")
#
# foo()
# bar()
def bar(): #基本函数
time.sleep(4)
print("in the bar")
def test1(func1): #装饰器--用来装饰基本函数,为其增加了计时器的功能
start_time = time.time()
func1() #func1 = bar -- print("in the bar")
stop_time = time.time()
print("func1 is running %s" %(stop_time - start_time))

def test2(func2):
print(func2)
return func2

print(test2(bar)) #bar 传的是bar对应的内存地址
test2(bar()) #bar()传的是bar()函数的内容

修饰器练习

原文:https://www.cnblogs.com/gaoxu366/p/9426111.html

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