首页 > 其他 > 详细

复习decorator

时间:2020-09-22 11:56:25      阅读:33      评论:0      收藏:0      [点我收藏+]

装饰器decorator复习,传递参数:

技术分享图片
 1 import time
 2 
 3 def timer(argv):
 4     def out_wraper(func):
 5         def wraper(a, b):
 6             print(In the %s % func)
 7             start_time = time.time()
 8             time.sleep(2)
 9             func(a, b)
10             stop_time = time.time()
11             print(the running time  of %s is:%s %(argv,(stop_time - start_time)))
12         return wraper
13     return out_wraper
14 
15 @timer(add)
16 def add(a, b):
17     print(a + b)
18 
19 
20 @timer(sub)
21 def sub(a, b):
22     print(a - b)
23 
24 
25 add(3, 5)
26 sub(8, 3)
View Code

 

复习decorator

原文:https://www.cnblogs.com/gzj137070928/p/13710391.html

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