KeyError: 1L in hash table

307 views
Skip to first unread message

Jayakumar Bellie

unread,
Jun 16, 2013, 3:51:15 AM6/16/13
to web...@googlegroups.com
I have to create a has table like
{ '1':'data1', '2':'data2', '10':'data3', '50':'data4' }

I get the data from the database, here is the code where I format the data

1        dataTypeList = {}
2        for row in result:
3           dataTypeList[row.number_indicator] = dataTypeList[row.data]

I get KeyError: 1L error in line 3

Jayakumar Bellie

unread,
Jun 16, 2013, 4:31:51 AM6/16/13
to web...@googlegroups.com
It is a mistake made my me I dont know how did I miss it, very bad.


dataTypeList[row.number_indicator] = dataTypeList[row.data]

it should be 

dataTypeList[row.number_indicator] = row.data

Niphlod

unread,
Jun 16, 2013, 8:15:36 AM6/16/13
to web...@googlegroups.com
how do you expect to run such code in a python environment ?
the first loop of that cycle tries to create a key within an empty dictionary with a value from an empty dictionary .... it's going to fail every time if row.data isn't in the dictionary yet.

Anthony

unread,
Jun 16, 2013, 8:27:26 AM6/16/13
to web...@googlegroups.com
Perhaps you meant to do:

    dataTypeList[row.number_indicator] = row.data

Anthony
Reply all
Reply to author
Forward
0 new messages