Unexpected result when comparing method with variable

Tony Meyer t-meyer at ihug.co.nz
Mon Apr 4 23:38:09 EDT 2005


[David Handy]
> I had a program fail on me today because the following didn't 
> work as I expected:
> 
> >>> class C:
> ...     def f(self):
> ...         pass
> ...
> >>> c = C()
> >>> m = c.f
> >>> m is c.f
> False
[...]
> The workaround really awkward:

What's wrong with this?

>>> class C:
... 	def f(self):
... 		pass
... 	def g(self):
... 		pass
... 	
>>> c = C()
>>> m = c.f
>>> m == c.f
True
>>> m == c.g
False

=Tony.Meyer




More information about the Python-list mailing list