[Python-Dev] Getting values stored inside sets

Paul Moore p.f.moore at gmail.com
Fri Apr 3 19:56:44 CEST 2009


2009年4月3日 R. David Murray <rdmurray at bitdance.com>:
> a == b
>> So, python calls a.__eq__(b)
>> Now, that function does:
>> a.key == b
>> Since b is an object with an __eq__ method, python calls
> b.__eq__(a.key).

That's the bit I can't actually find documented anywhere.
Ah, looking again I see that I misread the section describing the rich
comparison methods:
"""
There are no swapped-argument versions of these methods (to be used
when the left argument does not support the operation but the right
argument does); rather, __lt__() and __gt__() are each other’s
reflection, __le__() and __ge__() are each other’s reflection, and
__eq__() and __ne__() are their own reflection.
"""
I read that as meaning that no "reversed" version was called, whereas
it actually means that __eq__ is its own reversed version - and so
gets called both times.
Thanks for helping me clear that up!
Paul.


More information about the Python-Dev mailing list

AltStyle によって変換されたページ (->オリジナル) /