[IronPython] int() and long() incompatibility
J. Merrill
jvm_cop at spamcop.net
Mon Oct 9 17:00:29 CEST 2006
I'm wondering if int('0x20') (without the explicit radix value 16) should work. Doesn't the '0x' prefix mean that it's a hex number, radix 16, unambiguously?
OTOH, I would not expect int('033') to interpret the value as if the radix is 8, because the "leading 0 means octal" convention is both very old and a really really really bad idea! But 0x prefix doesn't mean anything else -- does it?
I'm waiting for the Pascal programmers to say that int('$20') should work, returning 32, because $ is the Pascal-language equivalent of '0x' -- but it shouldn't. To someone entering data into a computer program, '$20' is not a value in hex, it's an amount of money!
At 10:26 AM 10/9/2006, Floris van Nee wrote
>I just checked it myself to see what works and what doesn't. You're right that it doesn't work when putting '0x' in front of it. However, when I just do int('20', 16) it returns 32, which is correct.
>
>It is a bit weird though, that int(hex(20), 16) returns an error and I think that should be fixed. [snip]
>
>On 10/9/06, Sanghyeon Seo <<mailto:sanxiyn at gmail.com>sanxiyn at gmail.com> wrote:
>>>> int('0x20', 16)
>ValueError: invalid integer number literal
>
>Same for long. Python library reference isn't clear on this point, but
>my reading doesn't support this misfeature since one can use radix 0
>to the same effect. Anyway, there are codes out there depending on
>this. :(
>
>--
>Seo Sanghyeon
J. Merrill / Analytical Software Corp
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20061009/a98c2fde/attachment.html>
More information about the Ironpython-users
mailing list