Skip to content

Instantly share code, notes, and snippets.

@PaulSebalu
Created March 18, 2022 11:35
Show Gist options
  • Save PaulSebalu/164a7825d19a8d8101b2b9a2aa164f45 to your computer and use it in GitHub Desktop.
Save PaulSebalu/164a7825d19a8d8101b2b9a2aa164f45 to your computer and use it in GitHub Desktop.
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