Problem comparing object graphs and trees

Duncan Booth duncan.booth at invalid.invalid
Fri Dec 15 09:10:32 EST 2006


raphael.marvie at gmail.com wrote:

> I swear I am not drunk, but why isn't a1 == a2 and worse why isn't a1
>== a1? Does someone have a clue and can explain to me this suprising
> behavior? (python 2.4.3 on Ubuntu 6.06).

Because the __cmp__ method doesn't return a boolean. It returns a value <0, 
0 or >0 according to the relative ordering of its arguments. You are 
returning True (1) when the values are equal and you should be returning 0. 

If ordering isn't defined for your objects then define __eq__ instead of 
__cmp__.




More information about the Python-list mailing list