Mailing List Archive

[issue5133] Error with Eval
New submission from David Nicol <david@theNicols.net>:

The single line statements:

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

both crash; while

eval("07") works fine

----------
components: None
messages: 80982
nosy: davidnicol
severity: normal
status: open
title: Error with Eval
type: compile error
versions: Python 2.6

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5133>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue5133] Error with Eval [ In reply to ]
Raymond Hettinger <rhettinger@users.sourceforge.net> added the comment:

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')

----------
nosy: +rhettinger
resolution: -> invalid
status: open -> closed

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5133>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue5133] Error with Eval [ In reply to ]
Ezio Melotti <ezio.melotti@gmail.com> added the comment:

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

----------
nosy: +ezio.melotti

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5133>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com