Created
May 23, 2013 08:46
-
-
Save yuuichi-fujioka/5633587 to your computer and use it in GitHub Desktop.
decorator sample
This file contains hidden or 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 | |
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