Skip to content

Instantly share code, notes, and snippets.

@abyx
Created May 11, 2010 21:55
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 abyx/397936 to your computer and use it in GitHub Desktop.
Save abyx/397936 to your computer and use it in GitHub Desktop.
never use 'self.' in methods again
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