By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,282 Members | 1,549 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,282 IT Pros & Developers. It's quick & easy.

Re: Question about sorted in Python 3.0rc1

P: n/a
josh logan <de************@gmail.comwrote:
>sorted(P) # throws TypeError: unorderable types Player() < Player()

The sorted function works when I define __lt__.
I must be misreading the documentation, because I read for the
documentation __cmp__ that it is called if none of the other rich
comparison functions are defined.
You're either misreading or forgetting that __eq__ and __ne__,
which you define, are rich comparison functions. __cmp__ will only
be called for a comparison when *none* of the rich comparison
functions are defined, not just the one in question.

--
\S -- si***@chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
"Frankly I have no feelings towards penguins one way or the other"
-- Arthur C. Clarke
her nu becomež se bera eadward ofdun hlęddre heafdes bęce bump bump bump
Sep 22 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Sep 22, 7:32*am, Sion Arrowsmith <si...@chiark.greenend.org.uk>
wrote:
josh logan *<dear.jay.lo...@gmail.comwrote:
sorted(P) # throws TypeError: unorderable types Player() < Player()
The sorted function works when I define __lt__.
I must be misreading the documentation, because I read for the
documentation __cmp__ that it is called if none of the other rich
comparison functions are defined.

You're either misreading or forgetting that __eq__ and __ne__,
which you define, are rich comparison functions. __cmp__ will only
be called for a comparison when *none* of the rich comparison
functions are defined, not just the one in question.

--
\S -- si...@chiark.greenend.org.uk --http://www.chaos.org.uk/~sion/
* *"Frankly I have no feelings towards penguins one way or the other"
* * * * -- Arthur C. Clarke
* *her nu becomež se bera eadward ofdun hlęddre heafdes bęce bump bump bump
Hello Sion,

When I don't define the __eq__ and __ne__ comparison functions, the
same unexpected behavior occurs.
Sep 22 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.