Python 2.4 and list of dictionary issues

Discussion in 'Python' started by Chris Stevens, Feb 8, 2010.

  1. Hi all,

    I'm a python newbie so please excuse me if I am missing something
    simple here. I am writing a script which requires a list of
    dictionaries (originally a dictionary of dictionaries, but I changed
    it to a list to try and overcome the below problem).

    Now my understanding is that you create the empty list, then append or
    add entries to it. Correct?

    Here is some code:

    userInfo = []
    ....
    userInfo.append( {
    'username' : uidString[0],
    ...
    'failedattempts' : int(0)
    })

    I'm not to sure on the bracketing here, but I have tried many
    combinations. The issue here is that I get a "IndexError: list index
    out of range" message on the line "userInfo.append( {"

    I wrote this script on a box with Python 2.6 and it worked fine.
    Moving it to a box with 2.4, and I get this error. I can't understand
    why i'm getting a list index out of range error when trying to append
    (not reference) a list?? I have also tried "+=", and
    userInfo(len(userInfo))= .... just get the same error.

    Could anyone shed some light on this?

    Thanks,
    Chris
     
    Chris Stevens, Feb 8, 2010
    #1
    1. Advertisements

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. Carl J. Van Arsdall
    Replies:
    1
    Views:
    437
    Raymond Hettinger
    Feb 16, 2006
  2. Ilias Lazaridis
    Replies:
    6
    Views:
    708
    Ilias Lazaridis
    Feb 21, 2006
  3. james_027
    Replies:
    1
    Views:
    524
    Marc 'BlackJack' Rintsch
    Aug 22, 2007
  4. Navkirat Singh
    Replies:
    6
    Views:
    5,131
    Navkirat Singh
    Jul 29, 2010
  5. OW Ghim Siong
    Replies:
    2
    Views:
    642
    Peter Otten
    Nov 30, 2010
  6. Fox

    dictionary within dictionary

    Fox, Mar 8, 2005, in forum: ASP General
    Replies:
    5
    Views:
    414
    Michael D. Kersey
    Mar 13, 2005
  7. Jaewoong kim Crossbreeze
    Replies:
    1
    Views:
    260
    Jaewoong kim Crossbreeze
    Apr 17, 2009
  8. Ayushi Dalmia

    Initialise dictionary of dictionary

    Ayushi Dalmia, Jan 23, 2014, in forum: Python
    Replies:
    4
    Views:
    133
    Ayushi Dalmia
    Jan 24, 2014
Loading...