Dictionary invalid token error

Tim Chase python.list at tim.thechases.com
Tue Oct 2 11:02:00 EDT 2007


> 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






More information about the Python-list mailing list