Created
November 10, 2012 14:45
-
-
Save maniartech/4051300 to your computer and use it in GitHub Desktop.
A python decorator that prints the number of time a function has been executed.
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 counter(func): | |
""" | |
A decorator that prints the number of time a function has been executed. | |
""" | |
counter.count = 0 | |
def wrapper(*args, **kwargs): | |
counter.count = counter.count + 1 | |
res = func(*args, **kwargs) | |
print func.__name__, "has been used : ", counter.count, "X" | |
return res | |
return wrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment