Python 3 __cmp__ semantic change?

Johannes Bauer dfnsonfsduifb at gmx.de
Thu Nov 20 16:38:51 EST 2008


Inyeol.Lee at gmail.com schrieb:
> On Nov 20, 1:18 pm, Johannes Bauer <dfnsonfsdu... at gmx.de> wrote:
>> Hello group,
>>
>> I'm porting some code of mine to Python 3. One class has the __cmp__
>> operator overloaded, but comparison doesn't seem to work anymore with that:
>>
>> Traceback (most recent call last):
>>   File "./parse", line 25, in <module>
>>     print(x < y)
>> TypeError: unorderable types: IP() < IP()
>>
>> Was there some kind of semantic change?
> 
> Overload __lt__ method.

Well, of course I could do that, but the python doc says:

"Called by comparison operations if rich comparison (see above) is not
defined."
http://www.python.org/doc/2.5.2/ref/customization.html

And my code works just fine with 2.5 - only on 3.0 it doesn't work
anymore. Why is that?

Regards,
Johannes

-- 
"Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit,
verlästerung von Gott, Bibel und mir und bewusster Blasphemie."
         -- Prophet und Visionär Hans Joss aka HJP in de.sci.physik
                         <48d8bf1d$0$7510$5402220f at news.sunrise.ch>



More information about the Python-list mailing list