Skip to content

Instantly share code, notes, and snippets.

@maniartech
Created November 10, 2012 14:45
A python decorator that prints the number of time a function has been executed.
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