Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Dictionary invalid token error

Reply
Thread Tools

Dictionary invalid token error

 
 
brad
Guest
Posts: n/a
 
      10-02-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?

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

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



 
Reply With Quote
 
 
 
 
Richard Brodie
Guest
Posts: n/a
 
      10-02-2007

"brad" <(E-Mail Removed)> wrote in message news:fdtlqo$t1t$(E-Mail Removed)...

> 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.


 
Reply With Quote
 
 
 
 
brad
Guest
Posts: n/a
 
      10-02-2007
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.
 
Reply With Quote
 
Tim Chase
Guest
Posts: n/a
 
      10-02-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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
This is an unexpected token. The expected token is 'NAME' =?Utf-8?B?Y2FzaGRlc2ttYWM=?= ASP .Net 2 07-13-2007 11:38 AM
Token pasting (## operator) - Add whitespace to a token Wessi C Programming 3 08-11-2005 01:02 PM
"token" "token sequence" "scalar variable" "vector" ?? G Fernandes C Programming 1 02-18-2005 05:32 AM
preprocessor, token concatenation, no valid preprocessor token Cronus C++ 1 07-14-2004 11:10 PM
Invalid token error s.caron ASP .Net 0 06-08-2004 04:07 PM



Advertisments