Created
July 2, 2015 17:35
-
-
Save bermanmaxim/d4ff86174fffcf65ec3f to your computer and use it in GitHub Desktop.
Bounding a Python method to an instance during its initialization
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 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