Created
May 11, 2010 21:55
-
-
Save abyx/397936 to your computer and use it in GitHub Desktop.
never use 'self.' in methods again
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 selfish(f): | |
def wrapper(self, *args, **kwargs): | |
f.func_globals.update(dict((x, getattr(self, x)) for x in dir(self))) | |
return f(self, *args, **kwargs) | |
return wrapper | |
class Test(object): | |
def foo(self): | |
print "foo!" | |
@selfish | |
def bar(self): | |
foo() # No need to prefix with "self." | |
# >>> Test().bar() | |
# foo! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment