-
-
Save PaulSebalu/164a7825d19a8d8101b2b9a2aa164f45 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 counts and prints the number of times a function has been executed | |
""" | |
def wrapper(*args, **kwargs): | |
wrapper.count = wrapper.count + 1 | |
res = func(*args, **kwargs) | |
print '{0} has been used: {1}x'.format(func.__name__, wrapper.count) | |
return res | |
wrapper.count = 0 | |
return wrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment