[docs] [issue29146] Confusing "invalid token" exception when integers have leading zero

John Parejko report at bugs.python.org
Tue Jan 3 16:12:51 EST 2017


New submission from John Parejko:

As described in PEP-3127, the "leading-zeros" formatting for octal was removed from python 3. This is a good thing(tm), but the recommendation of that PEP to improve the error message of the raised exception[1] was apparently never implemented. I just ran into this while with some recently-ported python2 code, and it took a while to figure out the problem.

Although this is going to be less of a problem with time as people convert to pure python3, it will be very helpful during the transition period.

>>> 0o007
7
>>> 007
  File "<stdin>", line 1
    007
      ^
SyntaxError: invalid token


1: https://www.python.org/dev/peps/pep-3127/#id17

----------
assignee: docs at python
components: 2to3 (2.x to 3.x conversion tool), Documentation, Interpreter Core
messages: 284591
nosy: John Parejko, docs at python
priority: normal
severity: normal
status: open
title: Confusing "invalid token" exception when integers have leading zero
type: behavior
versions: Python 3.5

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29146>
_______________________________________


More information about the docs mailing list