assymetry between a == b and a.__eq__(b)
Mel Wilson
mwilson at the-wire.com
Fri Dec 3 16:10:21 EST 2004
In article <Qtqrd.177755$HA.59149 at attbi_s01>,
Steven Bethard <steven.bethard at gmail.com> wrote:
>I believe what Peter Otten was pointing out is that calling __eq__ is
>not the same as using ==, presumably because the code for == checks the
>types of the two objects and returns False if they're different before
>the __eq__ code ever gets called.
Doesn't seem to:
Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> class EQ(object):
... def __eq__ (self, other):
... return True
...
>>> eq = EQ()
>>> eq == 3
True
>>> 3 == eq
True
>>> class NEQ(object):
... def __eq__ (self, other):
... return False
...
>>> neq=NEQ()
>>> eq == neq
True
>>> neq == eq
False
>>>
Regards. Mel.
More information about the Python-list
mailing list