码迷,mamicode.com
首页 > 编程语言 > 详细

python @

时间:2015-10-14 17:32:18      阅读:161      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!