__author__ = 'bruce'
class Entry_Exit(object):
def __init__(self,f):
self.f = f
def __call__(self):
print "Enter " ,self.f.__name__
self.f()
print 'Exit' ,self.f.__name__
def Entry_Exit_Func(f):
def new_func():
print "Enter_function_decorator ",f.__name__
f()
print "Exit_function_decorator" ,f.__name__
return new_func
@Entry_Exit
@Entry_Exit_Func
def func1():
print "inside func1()"
@Entry_Exit
@Entry_Exit_Func
def func2():
print "inside func2()"
if __name__ == '__main__':
func1()
func2()
Enter new_func
Enter_function_decorator func1
inside func1()
Exit_function_decorator func1
Exit new_func
Enter new_func
Enter_function_decorator func2
inside func2()
Exit_function_decorator func2
Exit new_func