Skip to content

Instantly share code, notes, and snippets.

@yuuichi-fujioka
Created May 23, 2013 08:46
Show Gist options
  • Save yuuichi-fujioka/5633587 to your computer and use it in GitHub Desktop.
Save yuuichi-fujioka/5633587 to your computer and use it in GitHub Desktop.
decorator sample
import functools
class mydeco:
def __init__(self, *args):
self.args = args
def __call__(self, func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
return func(*args, **kwargs)
return wrapper
@mydeco('hello', 'world')
def myfunc(foo, bar):
print foo,bar
# above code equal forrow code
def myfunc(foo, bar):
print foo,bar
myfunc = mydeco('hello', 'world')(myfunc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment