Created
September 1, 2014 08:31
-
-
Save jorge-lavin/752d92a42f18007ee344 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Slightly adapted from http://www.artima.com/weblogs/viewpost.jsp?thread=240808 | |
# Tested under Python 2.6.6, 3.4.1 | |
def entryExit(f): | |
""" | |
This decorator adds the funcionality defined in new_f() | |
""" | |
def new_f(): | |
""" | |
Adds a entering-exiting message to function calls | |
""" | |
print('Entering {0}'.format (f.__name__)) | |
return_value = f() | |
print('Exited {0}'.format(f.__name__)) | |
return return_value | |
#Function name is preserved, if we don't want it comment next line | |
new_f.__name__ = f.__name__ | |
return new_f | |
@entryExit | |
def func1(): | |
""" | |
@return 1: | |
""" | |
print('Now inside func1()') | |
return 1 | |
@entryExit | |
def func2(): | |
""" | |
@return 2: | |
""" | |
print('Now inside func2()') | |
return 2 | |
if __name__ == '__main__': | |
print(func1()) | |
print(func2()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment