strange behavior of the comparison operator

Grant Edwards grante at
Wed Aug 29 23:01:44 CEST 2001

In article <mailman.999108615.24410.python-list at>, Ignacio Vazquez-Abrams wrote:
> On Wed, 29 Aug 2001, Grant Edwards wrote:
>> The only problem I see is that the case where self.r==other.r and self.i >
>> other.i isn't handled.  That wouldn't cause the problem you've observed, but
>> I'd do something like:
>>   def __comp__(self, other):
>>     if self.r < other.r:
>>        return -1
>>     elif self.r > other.r:
>>        return 1
>>     else:
>>        if self.i < other.i:
>>           return -1
>>        elif self.i > other.i:
>>           return 1
>>        else:
>>           return 0
> Mmm, no. You see, what if you have values like (5+1j) and (2+58j)? are you
> sure you want to believe that (5+1j) is larger?

That's the requirement he specified.  I was fixing the code to
meet the requirement.  [It turns out the actual problem was the
method name, right?]

If you want to argue about the requirements, that's entirely

> It will seem that way if you use the comparison function above.

Yup. That's what he said he wanted.

Grant Edwards                   grante             Yow!  I brought my BOWLING
                                  at               BALL -- and some DRUGS!!

More information about the Python-list mailing list