String to Hex

Peter Otten __peter__ at web.de
Wed Oct 27 16:59:15 EDT 2004


Michael Foord wrote:

>> One (fragile) way to avoid that Python 2.3 interprets
>> 0x80000000...0xffffffff (on 32-bit systems) as negative integers is to
>> add an explicit sign:

> Looks good. Why is it fragile ?

>>> int("0x80000000", 0), int("+0x80000000", 0)
(-2147483648, 2147483648L)

Dunno. Is it only me feeling the itch to remove the redundant-looking +
sign?

>>> int("-0x80000000", 0) == 0x80000000
True

Is that the equality you want to bury somewhere in a script? The fact that
the int() argument probably is a variable rather than a string constant
makes it only worse.
I'd say there is one more reason to look forward to Python 2.4.

Peter




More information about the Python-list mailing list