471,350 Members | 1,589 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

Dictionary invalid token error

This works:
>>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

Oct 2 '07 #1
3 4511
This works:
>
>>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

Oct 2 '07 #2

"brad" <by*******@gmail.comwrote in message news:fd**********@solaris.cc.vt.edu...
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.
Oct 2 '07 #3
Tim Chase wrote:
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.
Oct 2 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by evan.cooch | last post: by
reply views Thread by s.caron | last post: by
3 posts views Thread by Twanger | last post: by
1 post views Thread by john wright | last post: by
reply views Thread by Ben Holness | last post: by
3 posts views Thread by Manuel | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.