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 :
<SPAN class="punctuation token">{</SPAN><SPAN class="string token">'16304760420000'</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="number token">1536639.422987029</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">7422834.91819194</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'16304760430000'</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="number token">1536594.1241931021</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">7422763.591562942</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'16304760440000'</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="number token">1536511.8395807743</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">7422768.880266264</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'16304760450000'</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="number token">1536457.3127869368</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">7422770.376654357</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>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 <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'J:\PythonDevelopment\ParcelsXY_Mojo\ParcelsMojo.gdb\LocalSlcoDept_ParcelsXY'</SPAN>
bucketFields <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'parcel_id'</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">'XCOORD'</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">'YCOORD'</SPAN><SPAN class="punctuation token">]</SPAN>
row_values <SPAN class="operator token">=</SPAN> list<SPAN class="punctuation token">(</SPAN>myDictionary<SPAN class="punctuation token">.</SPAN>items<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
cursor <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>InsertCursor<SPAN class="punctuation token">(</SPAN>bucket<SPAN class="punctuation token">,</SPAN>bucketFields<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> row_values<SPAN class="punctuation token">:</SPAN>
cursor<SPAN class="punctuation token">.</SPAN>insertRow<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN> 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?