Created
February 14, 2020 21:01
-
-
Save dchuvardynskyi/6c0a4dc369c44b117bdd69e7258affc8 to your computer and use it in GitHub Desktop.
Count Calls Decorators
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
| import functools | |
| def count_calls(func): | |
| @functools.wraps(func) | |
| def wrapper_count_calls(*args, **kwargs): | |
| wrapper_count_calls.num_calls += 1 | |
| print(f"Call {wrapper_count_calls.num_calls} of {func.__name__!r}") | |
| return func(*args, **kwargs) | |
| wrapper_count_calls.num_calls = 0 | |
| return wrapper_count_calls |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment