eval('07') works, eval('08') fails, why?

Alex van der Spek amvds at xs4all.nl
Thu Jan 8 10:31:45 CET 2009


I am baffled by this:

IDLE 1.2.2      ==== No Subprocess ====
>>> input()
07
7
>>> input()
08
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    input()
  File "<string>", line 1
    08
     ^
SyntaxError: invalid token

of course, I can work around this using raw_input() but I want to 
understand why this happens. It boils down to:

>>> eval('07')
7
>>> eval('08')
Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    eval('08')
  File "<string>", line 1
    08
     ^
SyntaxError: invalid token

I can't think of anything that could cause this. Similarly, eval('09') 
fails, but for string 0x with x<8 it works. I am teaching myself Python 
in order to climb the ladder from Algol(1980s)-->Pascal(1990s)--
>VisualBasic(2000)-->Python. I am a physicist, have programmed computers 
all my life but I won't understand the real tech jargon of present day 
computer science. Please keep it simple

Thanks in advance,
Alex van der Spek



More information about the Python-list mailing list