python核心编程-函数-装饰器
2015-12-01 23:48
716 查看
#!/usr/bin/env python # -*- coding: UTF-8 -*- from time import ctime,sleep def tsfunc(func): '''装饰器''' def wrappedFunc(): print '[%s] %s() called' % (ctime(),func.__name__) return func() return wrappedFunc @tsfunc def foo(): pass foo() sleep(4) for i in range(3): sleep(1) foo()
输出
D:\Python27\test>func5.py [Tue Dec 01 22:29:50 2015] foo() called [Tue Dec 01 22:29:55 2015] foo() called [Tue Dec 01 22:29:56 2015] foo() called [Tue Dec 01 22:29:57 2015] foo() called D:\Python27\test>
相关文章推荐
- 永久修改python默认的字符编码为utf-8
- python核心编程-函数-内嵌函数
- leetcode Divide Two Integers python
- 用python产生一个好的秘钥
- dota玩家与英雄契合度的计算器,python语言scrapy爬虫的使用
- python 字符串连接 小知识点
- 使用 python脚本获取函数调用关系
- 最全Pycharm教程(4)——有关Python解释器的相关配置
- Python3 实现网站后台弱口令爆破(多线程)
- python 文件操作总结
- Python 多线程
- Python 多进程
- 【转】python的内建函数:filter,map,reduce,lambda,sorted等
- notepad++配置python
- Python-sublime构建Python运行,调试环境
- Python:计算一段代码的执行时间
- Python几个标准类型内建函数
- re.split() Python
- Python&Thrift--Server&Client
- python入门--列表list和元祖tuple