Last active
December 17, 2015 17:19
-
-
Save Nurdok/5645093 to your computer and use it in GitHub Desktop.
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 withenv(name): | |
def inenv(func): | |
def new_func(*args, **kwargs): | |
print 'withenv {}'.format(name) | |
func(*args, **kwargs) | |
return new_func | |
return inenv | |
def withenv_byname(func): | |
def new_func(self, *args, **kwargs): | |
withenv(self.name)(func)(self, *args, **kwargs) | |
return new_func | |
class Foo(object): | |
def __init__(self, name): | |
self.name = name | |
@withenv_byname | |
def run(self): | |
print 'hello!!' | |
f = Foo('worker-0') | |
f.run() |
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 withenv(name): | |
def inenv(func): | |
def new_func(*args, **kwargs): | |
print 'withenv {}'.format(name) | |
func(*args, **kwargs) | |
return new_func | |
return inenv | |
class Foo(object): | |
def __init__(self, name): | |
self.name = name | |
def withenv_byname(func): | |
def new_func(self, *args, **kwargs): | |
withenv(self.name)(func)(self, *args, **kwargs) | |
return new_func | |
@withenv_byname | |
def run(self): | |
print 'running...' | |
if __name__ == '__main__': | |
f = Foo('my foo') | |
f.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment