Created
April 11, 2016 14:36
-
-
Save thiagoh/03dceb4b03fb426376c7b17835fe5a39 to your computer and use it in GitHub Desktop.
wrapped functions: how it works
This file contains 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
# https://docs.python.org/2/library/functools.html#functools.update_wrapper | |
from functools import wraps | |
def wrapped_func1(func): | |
def __inner_func(): | |
return func() | |
return __inner_func | |
def wrapped_func2(func): | |
@wraps(func) | |
def __inner_func(): | |
return func() | |
return __inner_func | |
@wrapped_func1 | |
def my_function1(): | |
pass | |
@wrapped_func2 | |
def my_function2(): | |
pass | |
print my_function1.__name__ | |
print my_function2.__name__ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment