Created
November 26, 2018 18:22
-
-
Save josemarcosrf/0e49a8346d6ba99e6378b820f6f5dc31 to your computer and use it in GitHub Desktop.
python @wraps example of use
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 decorator(f): | |
@wraps(f) | |
def wrapper(*args, **kwargs): | |
print("I am the wrapper, wrapping '{}'".format(f.__name__)) | |
return f(*args, **kwargs) | |
return wrapper | |
@decorator | |
def hello(name): | |
print("Hey there {}".format(name)) | |
hello("world") | |
# I am the wrapper, wrapping 'hello' | |
# Hey there marcos | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment