Re: Question about sorted in Python 3.0rc1

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sion Arrowsmith

    Re: Question about sorted in Python 3.0rc1

    josh logan <dear.jay.logan @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
    >documentatio n __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 -- siona@chiark.gr eenend.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
  • josh logan

    #2
    Re: Question about sorted in Python 3.0rc1

    On Sep 22, 7:32 am, Sion Arrowsmith <si...@chiark.g reenend.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.gr eenend.org.uk --http://www.chaos.org.u k/~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.

    Comment

    Working...