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
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
--
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
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
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
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