Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with Eval #49383

Closed
davidnicol mannequin opened this issue Feb 2, 2009 · 3 comments
Closed

Error with Eval #49383

davidnicol mannequin opened this issue Feb 2, 2009 · 3 comments
Labels
build The build process and cross-build

Comments

@davidnicol
Copy link
Mannequin

davidnicol mannequin commented Feb 2, 2009

BPO 5133
Nosy @rhettinger, @ezio-melotti

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2009-02-02.19:02:54.879>
created_at = <Date 2009-02-02.18:52:30.828>
labels = ['build', 'invalid']
title = 'Error with Eval'
updated_at = <Date 2009-02-02.19:04:12.212>
user = 'https://bugs.python.org/davidnicol'

bugs.python.org fields:

activity = <Date 2009-02-02.19:04:12.212>
actor = 'ezio.melotti'
assignee = 'none'
closed = True
closed_date = <Date 2009-02-02.19:02:54.879>
closer = 'rhettinger'
components = ['None']
creation = <Date 2009-02-02.18:52:30.828>
creator = 'davidnicol'
dependencies = []
files = []
hgrepos = []
issue_num = 5133
keywords = []
message_count = 3.0
messages = ['80982', '80984', '80985']
nosy_count = 3.0
nosy_names = ['rhettinger', 'ezio.melotti', 'davidnicol']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = 'compile error'
url = 'https://bugs.python.org/issue5133'
versions = ['Python 2.6']

@davidnicol
Copy link
Mannequin Author

davidnicol mannequin commented Feb 2, 2009

The single line statements:

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

both crash; while

eval("07") works fine

@davidnicol davidnicol mannequin added the build The build process and cross-build label Feb 2, 2009
@rhettinger
Copy link
Contributor

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

@ezio-melotti
Copy link
Member

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

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build The build process and cross-build
Projects
None yet
Development

No branches or pull requests

2 participants