How do you check whether a python method is bound or not?
<p>Given a reference to a method, is there a way to check whether the method is bound to an object or not?  Can you also access the instance that it's bound to?</p>

<pre><code>def isbound(method):
    return method.im_self is not None

def instance(bounded_method):
    return bounded_method.im_self
</code></pre>

<p><a href="http://docs.python.org/ref/types.html">User-defined methods:</a></p>

<blockquote>
  <p>When a user-defined method object is
  created by retrieving a user-defined
  function object from a class, its
  <code>im_self</code> attribute is <code>None</code> and 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
  <code>im_self</code> attribute is the instance, and
  the method object is said to be bound.
  In either case, the new method's
  <code>im_class</code> attribute is the class from
  which the retrieval takes place, and
  its <code>im_func</code> attribute is the original
  function object.</p>
</blockquote>

<p>In Python <a href="http://docs.python.org/dev/whatsnew/2.6.html">2.6 and 3.0</a>:</p>

<blockquote>
  <p>Instance method objects have new
  attributes for the object and function
  comprising the method; the new synonym
  for <code>im_self</code> is <code>__self__</code>, and <code>im_func</code>
  is also available as <code>__func__</code>. The old
  names are still supported in Python
  2.6, but are gone in 3.0.</p>
</blockquote>
