首页 > 其他 > 详细

装饰器

时间:2018-07-16 22:09:46      阅读:212      评论:0      收藏:0      [点我收藏+]
# _*_coding:utf-8_*_
# Author:len liu
import time

def bar():
# start_time=time.time()
time.sleep(1)
print(‘in the bar‘)
# stop_time=time.time()

# print(‘use time %s ‘ %use_time) #bar() -------------->

                                                #in the bar
                                                #use time 1.000830888748169



def timer(fun):
def add_use_time():
start_time=time.time()
fun()
stop_time=time.time()
print(‘use time %s ‘ %(stop_time - start_time))
return add_use_time

bar=timer(bar)
bar()
#--------------> #in the bar
          #use time 1.000830888748169

装饰器

原文:https://www.cnblogs.com/len1028/p/9320661.html

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