Re: Question about sorted in Python 3.0rc1

2008-09-24 Thread Hrvoje Niksic
josh logan <[EMAIL PROTECTED]> writes: > It looks like __cmp__ is still in the documentation, and it seems to > work somewhat in Python 3.0rc1. Here is the link to the documnetation > http://docs.python.org/dev/3.0/reference/datamodel.html#object.__cmp__ Thanks, I've now filed a bug report for th

Re: Question about sorted in Python 3.0rc1

2008-09-22 Thread Terry Reedy
josh logan wrote: Here is a minimal example showing the problematic behavior. class Int(): def __init__(self, i): self.i = i def __cmp__(self, other): return cmp(self.i, other.i) Is = [Int(i) for i in range(8)] Is.sort() # throws TypeError: unorderable types Int() < Int

Re: Question about sorted in Python 3.0rc1

2008-09-22 Thread josh logan
On Sep 22, 9:29 am, Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > josh logan <[EMAIL PROTECTED]> writes: > > 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 > >

Re: Question about sorted in Python 3.0rc1

2008-09-22 Thread Hrvoje Niksic
josh logan <[EMAIL PROTECTED]> writes: > 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 > co

Re: Question about sorted in Python 3.0rc1

2008-09-22 Thread josh logan
On Sep 22, 7:32 am, Sion Arrowsmith <[EMAIL PROTECTED]> wrote: > josh logan  <[EMAIL PROTECTED]> wrote: > > >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 > >

Re: Question about sorted in Python 3.0rc1

2008-09-22 Thread Arnaud Delobelle
On 22 Sep, 11:52, josh logan <[EMAIL PROTECTED]> wrote: > On Sep 22, 3:41 am, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > > > > > On 22 Sep, 04:05, josh logan <[EMAIL PROTECTED]> wrote: > > > > Hello, > > > > I have 2 questions. Say I have this class: > > > > class Player(object): > > > def _

Re: Question about sorted in Python 3.0rc1

2008-09-22 Thread Sion Arrowsmith
josh logan <[EMAIL PROTECTED]> wrote: >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 >comparis

Re: Question about sorted in Python 3.0rc1

2008-09-22 Thread Peter Otten
josh logan wrote: > A better example would be sorting by increasing last name and > decreasing first name. This would be easy with the sort function > comparator, but I can't see how to do the same with the key argument. > Is the only solution to decorate the Player objects in another class > that

Re: Question about sorted in Python 3.0rc1

2008-09-22 Thread josh logan
On Sep 22, 3:41 am, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > On 22 Sep, 04:05, josh logan <[EMAIL PROTECTED]> wrote: > > > > > Hello, > > > I have 2 questions. Say I have this class: > > > class Player(object): > >     def __init__(self, fname, lname, score): > >         self.score = score > >

Re: Question about sorted in Python 3.0rc1

2008-09-22 Thread Arnaud Delobelle
On 22 Sep, 04:05, josh logan <[EMAIL PROTECTED]> wrote: > Hello, > > I have 2 questions. Say I have this class: > > class Player(object): > def __init__(self, fname, lname, score): > self.score = score > self.fname = fname > self.lname = lname > def __cmp__(self, oth

Question about sorted in Python 3.0rc1

2008-09-21 Thread josh logan
Hello, I have 2 questions. Say I have this class: class Player(object): def __init__(self, fname, lname, score): self.score = score self.fname = fname self.lname = lname def __cmp__(self, other): return (-cmp(self.score, other.score) or cmp