Skip to content

Instantly share code, notes, and snippets.

@ccorcos
Created November 18, 2014 04:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ccorcos/024656270586c7c85ccc to your computer and use it in GitHub Desktop.
Save ccorcos/024656270586c7c85ccc to your computer and use it in GitHub Desktop.
example of how python decorators, *args and **kwargs work
# 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