Created
May 4, 2017 21:17
-
-
Save hanxiao/11883419dbb9bf41c03e431b8f55e6bd to your computer and use it in GitHub Desktop.
python decorator wrapper function
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
def wrapper(v:int = 0): | |
def f2(f): | |
def f2_v(*args, **kwargs): | |
return f(*args, **kwargs) + v | |
return f2_v | |
return f2 | |
@wrapper(v=4) | |
def foo(x:int): | |
return 3+x | |
@wrapper(v=4) | |
def foo2(x:int, y: int): | |
return 3+x*y | |
print(foo(1)) | |
print(foo2(1,6)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment