Discussion:
Dictionary invalid token error
brad
2007-10-02 15:00:14 UTC
Permalink
Numbers with leading zeros are parsed as octal. 8 and 9 are invalid
digits in octal. Thus, it falls over. 00 through 07 will work fine,
but 08 and 09 will go kaput.
http://docs.python.org/ref/integers.html
-tkc
Thanks... that makes sense. I'll store them as strings.
Richard Brodie
2007-10-02 14:58:06 UTC
Permalink
Why does 09 cause an invalid token while 9 does not?
9 isn't a valid octal digit. You probably want to use strings for
storing telephone number like codes, if leading zeroes are
significant.
brad
2007-10-02 14:49:57 UTC
Permalink
area_group = {001:06, 002:04, 003:04, 006:9}
This does not (one the end, 09 is used instead of 9)
area_group = {001:06, 002:04, 003:04, 006:09}
File "<stdin>", line 1
area_group = {001:06, 002:04, 003:04, 006:09}
SyntaxError: invalid token

Why does 09 cause an invalid token while 9 does not?

###############################################

Python 2.4.4 (#2, Apr 5 2007, 18:43:10)
[GCC 4.1.2 20061115 (prerelease) (Debian AMD64 4.1.1-21)] on linux2
Tim Chase
2007-10-02 15:02:00 UTC
Permalink
Post by brad
area_group = {001:06, 002:04, 003:04, 006:9}
This does not (one the end, 09 is used instead of 9)
area_group = {001:06, 002:04, 003:04, 006:09}
File "<stdin>", line 1
area_group = {001:06, 002:04, 003:04, 006:09}
SyntaxError: invalid token
Why does 09 cause an invalid token while 9 does not?
Numbers with leading zeros are parsed as octal. 8 and 9 are
invalid digits in octal. Thus, it falls over. 00 through 07
will work fine, but 08 and 09 will go kaput.

http://docs.python.org/ref/integers.html

-tkc

Loading...