What happened to __cmp__() in Python 3.x?
breamoreboy at yahoo.co.uk
Sun Aug 16 13:49:16 CEST 2009
Chris Rebert wrote:
> On Sat, Aug 15, 2009 at 8:09 AM, Xavier Ho<contact at xavierho.com> wrote:
>> Hey all,
>> I've recently made my way to Python 3.1 and I'm not seeing __cmp__() in the
>> Is there a substitution for this special method in 3.1, or do I really have
>> to define all six rich comparison methods to work it out?
> I don't think so. Quoting
> "There are no swapped-argument versions of [the comparison] 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 believe this means you only need to define one method from each of
> the following pairs to get all the operators working:
> * __eq__ or __ne__
> * __lt__ or __gt__
> * __ge__ or __le__
Unfortunately I don't think it's that easy, see.
The issue referenced is still open. This of course assumes that I've
posted the correct link this time!
More information about the Python-list