cmp
Matt Russell
mattsurf76 at hotmail.com
Thu Dec 27 09:06:03 EST 2001
Well, I just made myself look silly. I admit it...
when I type 1==1 into the interpreter, I thought if it was true, the
result is 1 - this is right. But cmp(1,1) actually returns 0 (in
accordance to the docs)
But why then are we given the mechanism to compare instances of
classes via the __cmp__ def ?
Collegues of mine have used this to return 1 (truth) if two instances
are equal (instanceA==instanceB).... this obviously wasn't the
intended purpose. (__cmp__ shuold return 0 if the result of cmp(a,b)
is to be trusted??
Perhaps then could someone explain to me how one compares classes
useing the == operator, or indeed if this bad programming practice.
I hope I didn't waste too much of guido's time when I posted a bug on
sourceforge :(
More information about the Python-list
mailing list