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@mrabarnett.plus.com> wrote:
On 06/05/2011 23:51, Cameron Simpson wrote:
On 06May2011 15:40, Ethan Furman<ethan@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@python.org
http://mail.python.org/mailman/listinfo/python-ideas