How does compare work?

Alex Martelli aleaxit at yahoo.com
Tue Feb 3 04:34:53 EST 2004


On Tuesday 27 January 2004 06:44 pm, Helmut Jarausch wrote:
   ...
> In my 'Python in a Nutshell' by Alex Martelli (a tremendously good
> book), 1st edition on page 91 (Special Methods) it reads
> __cmp__  ......
> ...............
>           When __cmp__ is also absent, order comparisons (<,<=,>,>=)
>           raise exceptions. Equality comparisons (==,!=), in this case,
>           become identity checks: x==y evaluates  id(x)==id(y) (i.e.,
>           x is y)
>
> end of quotation.
> I wish this were true for the current Python implementation.

Thanks for pointing out the error in the first sentence you quote; what the 
sentence _should_ say, to describe Python's current implementation, is that 
when none of the specific (__lt__ etc) nor generic (__cmp__) methods are 
present, comparisons of objects default to comparisons of their id() values.

I apologize for my mistake.  Could I ask you to be so kind as to post this 
issue to the errata page, http://www.oreilly.com/catalog/pythonian/errata/ ?
By far the best way to get future printings fixed is for a reader to submit
errata, so it goes through the editorial process and comes to me for fixing.

Thanks!


Alex





More information about the Python-list mailing list