Skip to content

Instantly share code, notes, and snippets.

@dansondergaard
Created November 27, 2017 08:16
Show Gist options
  • Save dansondergaard/10454bdb08982e9c1d206edb05c26dbf to your computer and use it in GitHub Desktop.
Save dansondergaard/10454bdb08982e9c1d206edb05c26dbf to your computer and use it in GitHub Desktop.
def call_count(func):
def wrapper(*args, **kwargs):
wrapper.call_count += 1
return func(*args, **kwargs)
wrapper.call_count = 0
return wrapper
@call_count
def foo(x):
return x + 1
foo(1)
foo(2)
print(foo.call_count)
foo(3)
print(foo.call_count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment