Created
February 18, 2012 03:42
-
-
Save Kindari/1857252 to your computer and use it in GitHub Desktop.
Bind unbound methods to instances
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 bind(method, instance, klass = None, setbound = True, name = None): | |
if klass is None: | |
klass = instance.__class__ | |
bound = method.__get__(instance, klass) | |
if setbound: | |
setattr(instance, name or method.__name__, bound) | |
return bound |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment