Has comparison of instancemethods changed between python 2.5 and 2.4?

Fredrik Lundh fredrik at pythonware.com
Fri Dec 15 12:53:35 EST 2006


Frank Niessink wrote:

 > However, the instance the two methods belong to are different, i.e.
 > id(callback) returns different values for the two methods.

are you using the *object* as the callback?  otherwise, that sentence 
doesn't make much sense; bound methods are generated on the fly, and the 
identity may or may not be reused, depending on how things are garbage 
collected:

 >>> f.bar
<bound method foo.bar of <__main__.foo object at 0x009D1BD0>>
 >>> id(f.bar)
10322248
 >>> id(f.bar)
10322328
 >>> id(f.bar)
10322328
 >>> id(f.bar)
10322328
 >>> id(f.bar), id(f.bar)
(10322328, 10322328)
 >>> map(id, (f.bar, f.bar, f.bar))
[10322328, 10322248, 10322368]

</F>




More information about the Python-list mailing list