Using dictionary instead of update cursor

Discussion created by englandgirl22 on Aug 19, 2011
Latest reply on Aug 22, 2011 by englandgirl22
Hi there,

I have a shapefile that has about 175,000 records and a table with about 3500 records and I need to update one of the fields based on a field in a separate table. 
The common value between the two items is FacilityID and so I want to search the table for 'FacilityID' and then take the 'Name' associated with that and then insert it into the shapefile where the 'FacilityID' matches.

I wrote a script using update cursor (for the first time) and then I realised this was going to take days to do so started to explore dictionaries.  I found this piece of code here, which I think is what I need to use:


but am struggling to apply it to what I need to do as I keep getting the following error:

"updateRow.Name = lookupDict[updateRow.Name]
KeyError: '0'"

As I am quite new to this, I'm sure it is something quite obvious and simple that I need to change so any help would be greatly appreciated.

Many thanks in advance.

import arcgisscripting, sys, string, os
gp = arcgisscripting.create()

lookupTbl         = "C:\\TableJuly.dbf"
tableToUpdateTbl  = "C:\\LinesJuly.shp"

lookupDict = {}
searchRows = gp.searchcursor(lookupTbl)
searchRow = searchRows.next()
while searchRow:
   lookupDict[searchRow.Name] = [searchRow.FacilityID, searchRow.Name]
   searchRow = searchRows.next()
   #print searchRow
del searchRow
del searchRows

updateRows = gp.updatecursor(tableToUpdateTbl)
updateRow = updateRows.next()
while updateRow:
   updateRow.Name = lookupDict[updateRow.Name]
   updateRow = updateRows.next()
del updateRow
del updateRows
del lookupDict