python装饰器学习
来源:互联网 发布:2015年度网络热词 编辑:程序博客网 时间:2024/05/01 22:48
在廖雪峰网站学习python的装饰器
习题:请编写一个decorator,能在函数调用的前后打印出'begin call'
和'end call'
的日志。
答案:
import functoolsdef log(func): @functools.wraps(func) def wrapper(*args,**kw): print "begin call" f = func(*args, **kw) print "end call" return f return wrapper@logdef test(): print "hello"test()
输出:
begin call
hello
end call
阅读全文
0 0
- Python装饰器学习
- Python装饰器学习
- Python装饰器学习
- Python装饰器学习
- python 装饰器学习
- Python装饰器学习
- python 装饰器学习
- Python装饰器学习
- Python装饰器学习
- Python装饰器学习
- python装饰器学习
- Python装饰器学习
- python学习-装饰器
- Python装饰器学习
- Python装饰器学习
- python 装饰器学习
- Python装饰器学习
- Python装饰器学习
- 引用类型
- vs 中调用QT的动态连接库
- android实时视频网络传输方案总结(一共有五套)
- Hbuilder 使用技巧
- C++/MFC-几种常用控件
- python装饰器学习
- Integer和int的区别,包装类,基本数据类型,区别
- 深入 Spring 系列之静态资源处理
- py pandas 库
- host
- 最小二乘法
- Java过滤器与SpringMVC拦截器关系和区别、Java监听器
- Java基础知识总结
- 23种设计模式之单例模式(线程安全)