Created
September 14, 2013 09:42
-
-
Save bveliqi/6560570 to your computer and use it in GitHub Desktop.
A simple python decorator.
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
def logcall(f): | |
def wrapper(*a, **opts): | |
print('calling ' + f.__name__) | |
f(*a, **opts) | |
print('called ' + f.__name__) | |
return wrapper | |
@logcall | |
def square(x): | |
print 'result: ' + str(x * x) | |
return x * x | |
square(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment