Java 企业应用
不要温柔的走入那个良夜

decorators i: introduction to python decorators

'''
Created on Aug 212013

@author: hailiang
'''
class myDecorator(object):
    
    def __init__(self, f):
        print 
"1:inside myDecorator.__init__()"
        self.f 
= f  # Prove that function definition has completed
 
    def __call__(self, args
=None):
        print 
"3:inside myDecorator.__call__()"
        self.f(args)
 
@myDecorator
def aFunction(args
=None):
    print 
"4:inside aFunction()"
    print args
 
print 
"2:Finished decorating aFunction()"
 
aFunction()
print 
"another call"
aFunction(args
="I have value")

posted on 2013-08-21 17:38 cpegtop 阅读(460) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: