Skip to content

Instantly share code, notes, and snippets.

@Kindari
Created February 18, 2012 03:42
Show Gist options
  • Save Kindari/1857252 to your computer and use it in GitHub Desktop.
Save Kindari/1857252 to your computer and use it in GitHub Desktop.
Bind unbound methods to instances
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