[Python-ideas] int('0x3241fca1')
Andrew Barnert
abarnert at yahoo.com
Thu Feb 6 14:03:44 CET 2014
On Feb 6, 2014, at 4:51, Ram Rachum <ram.rachum at gmail.com> wrote:
> On Thu, Feb 6, 2014 at 2:47 PM, Andrew Barnert <abarnert at yahoo.com> wrote:
>> On Feb 6, 2014, at 4:44, Ram Rachum <ram.rachum at gmail.com> wrote:
>>
>>> Ah, you're talking about non-programmers. I can't imagine though a non-programmer seriously complaining that "0x0" is a number while "0z" isn't.
>>
>> Can you please read the whole sentence before replying to it? I specifically said "Would a newbie--or a non-programmer using a program--understand..."
>>
>> And you can't imagine a non-programmer complaining that "0123" is either not a number, or the number 83?
>
> You're right. I suggest int would just throw away the leading zeroes. In Python 3.x there's no meaning to them without 0o or 0x or 0b anyway, right?
As a literal in Python source, there are good reasons for it to be an error--because in Python 2.x, in many other languages, in various shell command invocations that you might want to convert from bash scripts to Python, etc., it means octal. Someone who types "0123" into Python source code could just as easily mean 83 as 123, and that's why it's an error.
As input from an end user, on the other hand, "0123" clearly means 123, not 83.
And that's a perfect example of why int(s) should not always do the same thing as the interactive interpreter. When you _want_ the same behavior as the interpreter, it's trivial to get it. When you want to treat end user data--or data from some file format or protocol, or whatever--as a string representation of an integer, rather than as a string representation of a Python integer literal--why shouldn't that be spelled int(s)?
>
>>
>>> On Thu, Feb 6, 2014 at 2:41 PM, Andrew Barnert <abarnert at yahoo.com> wrote:
>>>> On Feb 6, 2014, at 4:35, Ram Rachum <ram.rachum at gmail.com> wrote:
>>>>
>>>>> On Thu, Feb 6, 2014 at 2:31 PM, Andrew Barnert <abarnert at yahoo.com> wrote:
>>>>>> On Feb 6, 2014, at 4:19, Ram Rachum <ram.rachum at gmail.com> wrote:
>>>>>>
>>>>>>> I don't understand... The newbie will pass '0x13412' to the int constructor by mistake and be surprised when it's parsed as hex? Doesn't make sense does it?
>>>>>>
>>>>>> Would a newbie--or a non-programmer using a program--understand why, say, "0X0" counts as a valid number but "0Z" doesn't?
>>>>>
>>>>> Since they're likely to get the same confusion while feeding literals to the Python shell, I think this is acceptable.
>>>>
>>>> You think it's acceptable that a non-programmer should have to understand the python shell to use any program written in Python?
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140206/3cd6e6a5/attachment-0001.html>
More information about the Python-ideas
mailing list