Would there be support for a more general cmp/__cmp__

Antoon Pardon apardon at forel.vub.ac.be
Fri Oct 21 02:53:20 EDT 2005


Op 2005-10-20, Steve Holden schreef <steve at holdenweb.com>:
> Antoon Pardon wrote:
>> 
> Ergo: use rich comparisons.

rich comparosons can only solve the problem partly.

Python does have the cmp function and that can give
totaly inconsistent results even when the order
defined by the rich comparison functions is consistent
but only partial.

I think it is a problem if cmp gives me the following
results.

>>>  a1 = foo(1)
>>>  a2 = foo(2)
>>>  b1 = foo(1)
>>>  b2 = foo(2)
>>>  cmp(a1,b1)
0
>>>  cmp(a2,b2)
0
>>>  cmp(a1,a2)
1
>>>  cmp(b1,a2)
1
>>>  cmp(a1,b2)
-1

It would be better if cmp would give an indication it
can't compare two objects instead of giving incorrect
and inconsistent results.

-- 
Antoon Pardon



More information about the Python-list mailing list