Python学习之路:装饰器实现,,import ti
Python学习之路:装饰器实现,,import ti
import timedef timer(func):#timer(test1) func=test1 def deco(): start_time=time.time() func()#run test1 stop_time=time.time() print(‘the func run time is %s‘%(stop_time-start_time)) return decodef test1(): time.sleep(3) print(‘in the test1‘)def test2(): time.sleep(3) print(‘in the test2‘)print(timer(test1))test1=timer(test1)test1()#----->deco#-------------------------------------------------------------------import timedef timer(func):#timer(test1) func=test1 def deco(): start_time=time.time() func()#run test1 stop_time=time.time() print(‘the func run time is %s‘%(stop_time-start_time)) return deco@timer #加装饰器 test1=timer(test1)def test1(): time.sleep(3) print(‘in the test1‘)@timer #加装饰器def test2(): time.sleep(3) print(‘in the test2‘)test1()test2()
Python学习之路:装饰器实现
相关内容
- 自带的 Print 函数居然会报错?,
- 古典问题:有一对兔子,从出生后第3个月起每个月都生
- 使用Python爬取腾讯房产的新闻,用的Python库:requests 、
- python3爬虫-使用requests爬取起点小说,,import req
- Python IF 条件判断,,if 语句用于控制程
- Python基础-生物信息:找出基因,生物学家使用字母A、
- python之小应用:读取csv文件并处理01数据串,,目的:读
- Python程序中的进程操作-进程同步(multiprocess.Lock),,
- [Python]sort与sorted高级技巧,,与其他语言不同,py
- 定义一个方法get_page(url),url参数是需要获取网页内容的
评论关闭