def isbound(method):
return method.im_self is not None
def instance(bounded_method):
return bounded_method.im_self
User-defined methods:
When a user-defined method object is
created by retrieving a user-defined
function object from a class, its
im_selfattribute isNoneand the
method object is said to be unbound.
When one is created by retrieving a
user-defined function object from a
class via one of its instances, its
im_selfattribute is the instance, and
the method object is said to be bound.
In either case, the new method’s
im_classattribute is the class from
which the retrieval takes place, and
itsim_funcattribute is the original
function object.
In Python 2.6 and 3.0:
Instance method objects have new
attributes for the object and function
comprising the method; the new synonym
forim_selfis__self__, andim_func
is also available as__func__. The old
names are still supported in Python
2.6, but are gone in 3.0.