Created
November 18, 2014 04:57
-
-
Save ccorcos/024656270586c7c85ccc to your computer and use it in GitHub Desktop.
example of how python decorators, *args and **kwargs work
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
# An example of how to make decorators and also how *args and **kwargs work. | |
from functools import partial | |
def wrapping(func): | |
def wrapper(func, *args, **kwargs): | |
# print "wrapper" | |
# print func | |
# print args | |
# printwrappergs | |
kwargs['custom'] = 1 | |
func(*args, **kwargs) | |
return partial(wrapper, func) | |
@wrapping | |
def dummy(*args, **kwargs): | |
print "im dumb" | |
print args | |
print kwargs | |
dummy(1,2,3,a=1,b=2,c=3) | |
# if you dont use @wrapping, you can call it like this: | |
# wrapping(dummy)(1,2,3,a=1,b=2,c=3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment