Skip to content

Instantly share code, notes, and snippets.

@bermanmaxim
Created July 2, 2015 17:35
Show Gist options
  • Save bermanmaxim/d4ff86174fffcf65ec3f to your computer and use it in GitHub Desktop.
Save bermanmaxim/d4ff86174fffcf65ec3f to your computer and use it in GitHub Desktop.
Bounding a Python method to an instance during its initialization
import types
class Test(object):
def __init__(self, method):
self.fruit = "apple"
self.method = types.MethodType(method, self)
def method(self):
print self.fruit
t = Test(method)
t.method()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment