python-
来源:互联网 发布:淘宝卖死人衣服视频 编辑:程序博客网 时间:2024/06/03 22:28
导入time模块的装饰器
#!/usr/bin/env python#coding:utf-8import timedef timer(fun): def mytime(): start_time = time.time() fun() stop_time = time.time() print "The fun runs %s" %(stop_time - start_time) return mytime@timerdef fun1(): print "fun1..." time.sleep(1)@timerdef fun2(): print "fun2..." time.sleep(2)@timerdef fon3(): print "fon3..." time.sleep(0.5)print fun1()print fun2()print fon3()
在这里我们对装饰器的理解就是,定义装饰器以后,我们可以更好的管理与控制我们的函数,在装饰器里面,我们可以导入一些公共模块,在有好多函数具有相同的模块时,我们可以直接写入装饰器,在对于运用此模块时,直接调用装饰器即可,此刻的我们不需要在每个函数里面相同的工作再做一遍,这大大节省了我们的时间,也大大的节约了内存空间。
阅读全文
0 0
- Python
- Python
- Python
- python
- Python
- PYTHON
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- python
- Python
- Servlet文件上传
- jQuery实现用户信息表格的添加、删除操作
- 51Nod 1241 特殊的排序
- 设计模式之禅—23种设计模式详解_1 单例模式
- http协议,请求报文,响应报文格式思维导图
- python-
- 面试题39(2). 判断是否为平衡二叉树
- (CSU
- 异步任务利器Celery(一)介绍
- angular表格排序(查询)
- 动态内存管理和智能指针 2.0 -- shared_ptr
- 什么时候用相对定位或绝对定位
- 设计模式之策略模式-Strategy Pattern
- 【2017 ACM/ICPC Asia Regional Shenyang Online 1004】hdu 6197 array array array