修饰器练习

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()函数的内容
posted @ 2018-08-05 16:07  亚格斯123  阅读(62)  评论(0编辑  收藏  举报