python装饰器
来源:互联网 发布:nginx tengine 哪个好 编辑:程序博客网 时间:2024/04/20 17:01
请见 http://www.cnblogs.com/huxi/archive/2011/03/01/1967600.html
多个参数的示例:
def mydecorator(arg1, arg2): print "level 1 : Arg1=%s, arg2=%s" % (arg1, arg2) def newdec(func): print 'level 2 : newdec was called. the arg is func=%s' % func def replace(self, x, y): print "level 3 : replace was called. self is %s, x=%s, y=%s" % (str(self), str(x), str(y)) return func(self, x, y) return replace return newdecclass A2: def __init__(self): pass @mydecorator('Hello', 'word.') def method(self, x, y): print x, yif __name__ == '__main__': a = A2() a.method(1, 2)运行结果为:
level 1 : Arg1=Hello, arg2=word.level 2 : newdec was called. the arg is func=<function method at 0x04A06130>level 3 : replace was called. self is <__main__.A2 instance at 0x04A05850>, x=1, y=21 2
- python装饰器装饰类
- [python]python装饰器
- Python装饰器学习
- Python装饰器
- python 装饰器
- Python装饰器
- python 装饰器 应用
- python 装饰器2
- Python装饰器学习
- python装饰器
- python装饰器
- python 装饰器入门
- python装饰器
- python装饰器
- python 装饰器'@'
- python装饰器
- Python装饰器详解
- python 装饰器
- GridView.Columns 属性----手工添加一列
- 什么是Ruby Ruby的简介
- MyWidget
- 关联映射-----一对多小实例
- jQuery 1.4.2 getJSON() 不能正常工作的原因
- python装饰器
- 浅谈android Toast五种样式 (让你的Toast更炫)
- Outlook Express中配置hotmail账号
- 调试的时候 才会走某些逻辑
- 基于主键的一对一小实例
- linux下安装mysql
- vim使用进阶: 在VIM中使用GDB调试 – 使用vimgdb
- PhoneGap(1.1.0)是如何工作的
- ubuntu 禁止gdm自动启动,启动到字符终端模式