How does Python distinguish callback function which is a member of a class?
<p>Please look at the simple example:</p>

<pre><code>class A:
  def __init__(self, flag):
    self.flag = flag

  def func(self):
    print self.flag

a = A(1)
b = A(2)
callback_a = a.func
callback_b = b.func

callback_a()
callback_b()
</code></pre>

<p>The result is:</p>

<pre><code>1
2
</code></pre>

<p>It runs as expected. But I have a question. In C, the callback function is passed as a pointer. In Python, it should have a similar way to do this, so the caller knows the address of the function. But in my example, not only the function pointer is passed, but also the parameter (self) is passed, because the same method of the same class prints different results. So my questions are:</p>

<ol>
<li><p>Does such a method in Python only has one copy in memory? My meaning is that the code of any method only has one copy, and in my example the method won't be cloned itself. I think it should have only one copy, but here I still make this question in order to get more inputs.</p></li>
<li><p>I remember everything in Python is an object. So in my example, are there two function instances with different parameters but only one copy of code?</p></li>
</ol>
