comparing str's with ints
Frank Tobin
ftobin at neverending.org
Mon Apr 29 19:40:02 EDT 2002
John Roth, on 2002-04-29, wrote:
> If you really, truely have to do Perl type comparisons between integers
> and strings, you might consider deriving your own integer and string
> types, and providing a custom __cmp__() method.
Oh, I certainly didn't want to do weakly-typed Perl-style comparisions.
It was a type error on my part to be comparing a str to an int (I had
expecting to be comparing an int to an int). Since no exception was
thrown, I expected that 'foo > 0' (foo was accidentally a string instead
of an int) was at least doing something sane, but obviously it wasn't (it
was doing the 'arbitrary but consistent' comparison).
--
Frank Tobin http://www.neverending.org/~ftobin/
More information about the Python-list
mailing list