Dictionary invalid token error

Discussion in 'Python' started by brad, Oct 2, 2007.

  1. brad

    brad Guest

    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
     
    brad, Oct 2, 2007
    #1
    1. Advertising

  2. "brad" <> wrote in message news:fdtlqo$t1t$...

    > 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.
     
    Richard Brodie, Oct 2, 2007
    #2
    1. Advertising

  3. brad

    brad Guest

    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.
     
    brad, Oct 2, 2007
    #3
  4. brad

    Tim Chase Guest

    > 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
     
    Tim Chase, Oct 2, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. s.caron

    Invalid token error

    s.caron, Jun 8, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    555
    s.caron
    Jun 8, 2004
  2. Cronus
    Replies:
    1
    Views:
    722
    Paul Mensonides
    Jul 15, 2004
  3. G Fernandes
    Replies:
    1
    Views:
    558
  4. Wessi
    Replies:
    3
    Views:
    915
    Lawrence Kirby
    Aug 11, 2005
  5. =?Utf-8?B?Y2FzaGRlc2ttYWM=?=

    This is an unexpected token. The expected token is 'NAME'

    =?Utf-8?B?Y2FzaGRlc2ttYWM=?=, Jul 13, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    828
    =?Utf-8?B?Y2FzaGRlc2ttYWM=?=
    Jul 13, 2007
Loading...

Share This Page