[Python-ideas] Improve readability of long numeric literals

Chris Angelico rosuav at gmail.com
Wed Feb 10 16:42:08 EST 2016


On Thu, Feb 11, 2016 at 5:00 AM, Random832 <random832 at fastmail.com> wrote:
> On Wed, Feb 10, 2016, at 12:51, Georg Brandl wrote:
>> Underscores are allowed anywhere in numeric literals, except:
>>
>> * at the beginning of a literal (obviously)
>> * at the end of a literal
>> * directly after a dot (since the underscore could start an attribute
>> name)
>
> I don't think it's particularly important to support this case, but the
> sequence digit/dot/name with no spaces between is a syntax error now,
> because the digit/dot is interpreted as a floating point constant.

Only if that's the only dot.

>>> 1._
  File "<stdin>", line 1
    1._
      ^
SyntaxError: invalid syntax
>>> 1.1._
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'float' object has no attribute '_'

I don't want to see the first one have an arbitrary new meaning. It'd
be confusing.

ChrisA


More information about the Python-ideas mailing list