首页 > 编程语言 > 详细

python @

时间:2015-10-14 17:30:00      阅读:174      评论:0      收藏:0      [点我收藏+]

test_\@.py

class myDecorator(object):
def __init__(self, f):
print "inside myDecorator.__init__()"
self.f = f

def __call__(self):
print "inside myDecorator.__call__()"
self.f()

@myDecorator
def aFunction():
print "inside aFunction()"

print "Finished decorating aFunction()"
aFunction()
print ‘\n‘

def entryExit(f):
def new_f():
print "Entering", f.__name__
f()
print "Exited", f.__name__
return new_f

@entryExit
def func1():
print "inside func1()"

func1()

 

执行结果

inside myDecorator.__init__()
Finished decorating aFunction()
inside myDecorator.__call__()
inside aFunction()


Entering func1
inside func1()
Exited func1

python @

原文:http://www.cnblogs.com/banwhui/p/4877810.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!