Created
August 20, 2019 20:48
-
-
Save waynew/addc38f6dc821e57be3666d2d0d5b96b to your computer and use it in GitHub Desktop.
Just some samples about wrapping code with decorators
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
import functools | |
def bloop(arg): | |
def wrapper(func): | |
@functools.wraps(func) | |
def f(*args, **kwargs): | |
print('le func name:', func.__name__, 'le func:', func) | |
return func(*args, **kwargs) | |
return f | |
return wrapper | |
def squizzy(arg): | |
def wrapper(func): | |
@functools.wraps(func) | |
def f(*args, **kwargs): | |
return func(*args, **kwargs) | |
return f | |
return wrapper | |
@squizzy('thing') | |
@bloop('hello') | |
def bar(): | |
print('Hi mom') | |
print('ok') | |
bar() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment