Re: Trouble with max() and __cmp__()

2007-01-28 Thread Gabriel Genellina
At Sunday 28/1/2007 18:21, Thomas Nelson wrote: <[EMAIL PROTECTED]> wrote: >Define method __gt__. This works, thanks. I was a little surprised though. is __cmp__ used by any builtin functions? The problem is, rich comparison functions take precedence over __cmp__, so if your base class (lis

Re: Trouble with max() and __cmp__()

2007-01-28 Thread Martin v. Löwis
Thomas Nelson schrieb: > On Jan 28, 3:13 pm, Wojciech Muła > <[EMAIL PROTECTED]> wrote: >> Define method __gt__. > > This works, thanks. I was a little surprised though. is __cmp__ used > by any builtin functions? It is used by max() if the object doesn't implement __gt__. Regards, Martin --

Re: Trouble with max() and __cmp__()

2007-01-28 Thread Thomas Nelson
On Jan 28, 3:13 pm, Wojciech Muła <[EMAIL PROTECTED]> wrote: >Define method __gt__. This works, thanks. I was a little surprised though. is __cmp__ used by any builtin functions? Thanks, THN -- http://mail.python.org/mailman/listinfo/python-list

Re: Trouble with max() and __cmp__()

2007-01-28 Thread Wojciech Muła
Thomas Nelson wrote: > My code: > > class Policy(list): > def __cmp__(self,other): > return cmp(self.fitness,other.fitness) Define method __gt__. -- http://mail.python.org/mailman/listinfo/python-list

Re: Trouble with max() and __cmp__()

2007-01-28 Thread Jean-Paul Calderone
On 28 Jan 2007 12:46:07 -0800, Thomas Nelson <[EMAIL PROTECTED]> wrote: >My code: > >class Policy(list): >def __cmp__(self,other): >return cmp(self.fitness,other.fitness) > >j = Policy() >j.fitness = 3 >k = Policy() >k.fitness = 1 >l = Policy() >l.fitness = 5 >print max([j,k,l]).fitness

Trouble with max() and __cmp__()

2007-01-28 Thread Thomas Nelson
My code: class Policy(list): def __cmp__(self,other): return cmp(self.fitness,other.fitness) j = Policy() j.fitness = 3 k = Policy() k.fitness = 1 l = Policy() l.fitness = 5 print max([j,k,l]).fitness prints 3, when I was expecting it to print 5. What have I done wrong? Thanks for