码迷,mamicode.com
首页 > 其他好文 > 详细

修饰器练习

时间:2018-08-05 16:56:55      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:time()   tar   fun   练习   地址   内存   imp   增加   run   

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()函数的内容

修饰器练习

标签:time()   tar   fun   练习   地址   内存   imp   增加   run   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!