[Python-ideas] 1_000_000

Calvin Spealman ironfroggy at gmail.com
Sat May 7 01:55:11 CEST 2011


On Fri, May 6, 2011 at 7:44 PM, Bruce Leban <bruce at leapyear.org> wrote:
> I'm opposed to changing int so that int('123_456') ignores the _ as that
> will change the behavior of existing code and could break apps.
> Alternatively, if you want to change int how about int('123_456',
> separator='_') ignores the _. That would also admit int('123,456',
> separator=',')
> --- Bruce
>
>
> On Fri, May 6, 2011 at 4:41 PM, MRAB <python at mrabarnett.plus.com> wrote:
>>
>> On 06/05/2011 23:51, Cameron Simpson wrote:
>>>
>>> On 06May2011 15:40, Ethan Furman<ethan at stoneleaf.us>  wrote:
>>> | Bruce Leban wrote:
>>> |>Is _ just ignored in numbers or are there more complex rules?
>>> |>
>>> |>     * 1_2345_6789  (can I use groups of other sizes instead?)
>>> |>     * 1_2_3_4_5  (ditto)
>>> |>     * 1_234_6789  (do all the groups need to be the same size?)
>>> |>     * 1_   (must the _ only be in between 2 digits?)
>>> |>     * 1__234   (what about multiple _s?)
>>> |>     * 9.876_543_210   (can it be used to the right of the decimal
>>> point?)
>>> |>     * 0xFEFF_0042   (can it be used in hex, octal or binary numbers?)
>>> |>     * int('123_456')   (do other functions accept this syntax too?)
>>> |
>>> | I would say it's ignored.  Have the rule be something like
>>> | number_string.replace('_','').
>>> |
>>> | The only wrinkle is that currently '_1' is usable name, and that
>>> | should probably be disallowed if the above change took place.
>>> |
>>> | I'm +1 on the idea.
>>>
>>> Personally I'm be for ignoring the _ also, save that I would forbid it
>>> at the start or end, so no _1 or 1_.
>>>
>>> And I would permit it in hex code etc.
>>>
>>> I'm +0.5, myself.
>>>
>> As far as I remember, Ada also permits it, but has the rule that it can
>> occur only between digits. If we follow that, then:
>>
>>    1_2345_6789 => Yes
>>    1_2_3_4_5 => Yes
>>    1_234_6789 => Yes
>>    1_ => No
>>    _1 => No
>>    1__234 => No
>>    9.876_543_210 => Yes
>>    9._876_543_210 => No
>>    9_.876_543_210 => No
>>    0xFEFF_0042 => Yes
>>    int('123_456') => Yes
>> _______________________________________________
>> Python-ideas mailing list
>> Python-ideas at python.org
>> http://mail.python.org/mailman/listinfo/python-ideas
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>
>

I am +0 on the whole idea, but +0.5 if is not an underscore, which I
think is ugly. Would it conflict with any other syntax rules if
numbers allowed a space separator?

for i in range(1 111 111):
    foo(i)

It looks cleaner and in a fixed-font should be just as obvious about
separator placement.

-- 
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://techblog.ironfroggy.com/
Follow me if you're into that sort of thing: http://www.twitter.com/ironfroggy



More information about the Python-ideas mailing list