This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Error with Eval
Type: compile error Stage:
Components: None Versions: Python 2.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: davidnicol, ezio.melotti, rhettinger
Priority: normal Keywords:

Created on 2009-02-02 18:52 by davidnicol, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg80982 - (view) Author: David Nicol (davidnicol) Date: 2009-02-02 18:52
The single line statements:

eval("08")  ; and
eval("09")

both crash; while

eval("07")  works fine
msg80984 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2009-02-02 19:02
They don't crash.  They raise a SyntaxError because the "08" and "09"
are invalid octal literals.

If you're working with decimal literals that are padded on the left with
zeroes, those need to be stripped off before conversion:

   '000987'.lstrip('0') --> '987'

Or, you can use the int() function:

   int('000987')
msg80985 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2009-02-02 19:04
The leading zero is used to define octal numbers, 8 and 9 are not valid
octal digits, see
http://docs.python.org/reference/lexical_analysis.html#integer-and-long-integer-literals

Also, you don't need to use eval to reproduce that behavior.

The number displayed is the decimal equivalent:
>>> 07
7
>>> 010
8
History
Date User Action Args
2022-04-11 14:56:45adminsetgithub: 49383
2009-02-02 19:04:12ezio.melottisetnosy: + ezio.melotti
messages: + msg80985
2009-02-02 19:02:54rhettingersetstatus: open -> closed
resolution: not a bug
messages: + msg80984
nosy: + rhettinger
2009-02-02 18:52:30davidnicolcreate