Strange behaviour of __cmp__
Robert Kern
rkern at ucsd.edu
Thu May 5 05:48:43 EDT 2005
janeaustine50 at hotmail.com wrote:
> See the following...
>
>
>>>>class X(list):
>
> def __cmp__(self,anX):
> print "comparing from",id(self)
> return cmp(self.v,anX.v)
>
>
>
>>>>x1=X()
>>>>x2=X()
>>>>x1.v=-1
>>>>x2.v=100
>>>>x1>x2
>
> False
>
>>>>x1<x2
>
> False
>
> I expected x1>x2 or x1<x2 were False and True respectively.
list.__lt__ and list.__gt__ are being used in preference to X.__cmp__.
Override these methods.
--
Robert Kern
rkern at ucsd.edu
"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
More information about the Python-list
mailing list