[Python-ideas] Improve readability of long numeric literals

Victor Stinner victor.stinner at gmail.com
Wed Feb 10 03:53:10 EST 2016


2016-02-09 22:40 GMT+01:00 Manuel CerĂ³n <ceronman at gmail.com>:
> Hi everyone!
>
> Sometimes it's hard to read long numbers. For example:
>
>>>> opts.write_buffer_size = 67108864
>
> Some languages (Ruby, Perl, Swift) allow the use of underscores in numeric
> literals, which are ignored.

Yeah, I saw this (in Perl) and I think that it's a good idea.


> Another option is to use spaces instead of underscores:
>
>>>> opts.write_buffer_size = 67 108 864

It sounds error-prone to me. It's common that I forget a comma in a tuple like :

x = (1,
     2
     3)

I expect a SyntaxError, not x = (1, 23).

It can also occur on a single line:  x = (1, 2 3)

> I have seen some old discussions around this, but nothing on this list or a
> PEP. With Python being use more and more for scientific and numeric
> computation, this is a small change that will help with readability a lot.
> And, as far as I can tell, it doesn't break compatibility in any way.

I'm not sure that a PEP is required. We just have to clarify where
underscore are allowed exactly. See the discussion above they are
corner cases on float and complex numbers.

Victor


More information about the Python-ideas mailing list