Strange behaviour of __cmp__

janeaustine50 at hotmail.com janeaustine50 at hotmail.com
Thu May 5 05:17:14 EDT 2005


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.




More information about the Python-list mailing list