Dictionary invalid token error

B

brad

This works:

This does not (one the end, 09 is used instead of 9)
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
 
R

Richard Brodie

brad said:
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.
 
T

Tim Chase

This works:
This does not (one the end, 09 is used instead of 9)

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top