RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
装饰器的使用

2022-09-17

永福网站建设公司创新互联,永福网站设计制作,有大型网站制作公司丰富经验。已为永福上千家提供企业网站建设服务。企业网站搭建\外贸营销网站建设要多少钱,请找那个售后服务好的永福做网站的公司定做!

装饰器的使用实例——获得计时函数所用时间:

 1 import time
 2 # 定义装饰器函数
 3 def decorator(fun):
 4     def inner():
 5         # 获得开始时间
 6         start = time.time()
 7         # 执行计时函数
 8         fun()
 9         # 执行计时函数之后所用的时间
10         end = time.time()
11         # 计时所用的时间
12         timing = end - start
13         print("计时消耗的时间为:",timing)
14     return inner
15 
16 @decorator
17 def work():
18     for i in range():
19         print(i)
20 
21 # 调用函数
22 work()

本文题目:装饰器的使用
文章路径:http://sczitong.cn/article/dsogsjg.html