AnsweredAssumed Answered

Using a dictionary or list with an Insert Cursor

Question asked by jborgion Champion on Sep 24, 2019
Latest reply on Sep 24, 2019 by jborgion

In this thread, I am creating a dictionary with which to use with an InsertCursor to add rows to an existing table. I can get the dictionary created okay, but I keep getting an error when I try to use it as the data source:

 

Traceback (most recent call last):

File "<ipython-input-4-ce36707b33ba>", line 3, in <module>
cursor.insertRow(row)

TypeError: sequence size must match size of the row

 

In another thread, Randy Burton suggests iterating though a dictionary so I'm attempting to follow his lead.

 

My dictionary looks like this :

 

{'16304760420000': (1536639.422987029, 7422834.91819194),
'16304760430000': (1536594.1241931021, 7422763.591562942),
'16304760440000': (1536511.8395807743, 7422768.880266264),
'16304760450000': (1536457.3127869368, 7422770.376654357)}

 

I fiddled around a bit with the dictionary itself, but didn't get too far, so after taking another look at the online help for InsertCursors, I turn the dictionary into a list and tried that:

 

bucket = r'J:\PythonDevelopment\ParcelsXY_Mojo\ParcelsMojo.gdb\LocalSlcoDept_ParcelsXY' 
bucketFields = ['parcel_id','XCOORD','YCOORD']

row_values = list(myDictionary.items())

cursor = arcpy.da.InsertCursor(bucket,bucketFields)
for row in row_values:   
    cursor.insertRow(row)

 I think my problem with this is the help page describes using the row_values list to insert a @SHAPE, but I just want to insert a row in a table where row[0] us the parcel_id, row[1][0] is the XCOORD and row[1][1] is the YCOORD.

 

How do I translate myDictionary key:(value1,value2) or  my row_values items into a form that the InsertCursor can handle?

Outcomes