Skip to content

Instantly share code, notes, and snippets.

@grihabor
Last active November 1, 2017 06:53
Show Gist options
  • Save grihabor/be970a0719a0a266e53dcdadcd8e9512 to your computer and use it in GitHub Desktop.
Save grihabor/be970a0719a0a266e53dcdadcd8e9512 to your computer and use it in GitHub Desktop.
Print the name of the function if decorated #practical
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