Is UserList.py "strange" or is it cmp()?
Tom Funk
_spam_sux_tdfunk at _spam_sux_nettally.com
Tue Mar 14 17:02:41 EST 2000
Hi, Alex.
Thanks for the response.
In an article posted 14 Mar 2000 14:37:49 -0500,
Alex (alex at somewhere.round.here) said:
> Usually, the way it's supposed to work is
>
> cmp (a, b) => -1 if a < b
> cmp (a, b) => 0 if a == b
> cmp (a, b) => 1 if a > b
True, consistent with the C library's strcmp() family.
>
> which is consistent with the results you got. I guess that 'a == b' is
> actually returning (not cmp (a, b))
>
> Alex.
Duh! Epiphany! I just got it!
cmp() and __cmp__() both function the same way: returning negative, zero
or positive values when comparing two objects -- cmp() is intended for
ORDERING items. The == operator takes the cmp() result and indicates
true (1) or false (0) if the two items are are equal (I.e., cmp(a,b)==0).
If we were to find the runtime function that handles "==", it might look
like this:
return cmp(pyObject1, pyObject2) == 0;
As you suggested, using:
return (not cmp(pyObject1, pyObject2));
would yield the same result.
But that doesn't tell us why testuserlist.py dies at this assertion:
assert u2[:I] == l2[:I]
Seems to me this assertion should pass.
--
-=< tom >=-
Thomas D. Funk | "Software is the lever
Software Engineering Consultant | Archimedes was searching for"
Advanced Systems Design, Tallahassee FL. |
More information about the Python-list
mailing list