Last active
November 1, 2017 06:53
-
-
Save grihabor/be970a0719a0a266e53dcdadcd8e9512 to your computer and use it in GitHub Desktop.
Print the name of the function if decorated #practical
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
from functools import wraps | |
def print_function_name(f): | |
@wraps(f) | |
def wrapper(*args, **kwargs): | |
print('Call: {}'.format(f.__name__)) | |
return f(*args, **kwargs) | |
return wrapper | |
@print_function_name | |
def square(x): | |
return x * x | |
print(square(3) + square(4)) | |
#|Call: square | |
#|Call: square | |
#|25 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment