Problem using arcpy Update cursor

المشرف العام

Administrator
طاقم الإدارة
I have python list which i want to use to update a feature class table in arcgis. Python list is not in the same order as the fields of table. So before making update i am matching the field names in list and the table. And if the match is found all the rows in the field are updated. And it again goes to check for next field name and so on.

here are first few elements of the list 'l'.

[[u'OBJECTID', 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0], [u'shape', None, None, None, None, None, None, None, None], [u'NAME_NUMMER',None, None, u'3239', u'2271',u'2271',u'2272',u'55',u'55'], [u'TYP', 1, 1, 1, 1, 19, 19, 19, 19], [u'STRANG_REF', None, None, None, None, 98.0, None, None, None], [u'SPANNUNG', 3.0, 3.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0], [u'ART', 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0], [u'QUERSCHNITT', None, None, None, None, None, None, None, None], [u'MATERIAL', None, None, None, None, None, None, None, None],Feature class table.



On comparing you will notice that the name of the fields in table and python list are same but they are not in the same order. Field 'TYP' is before 'STRANG_REF'.

The values in python list are also different which has to be copied in the FC table.

Code:

fc = "C:/.../A_sel"fields = [f.name for f in arcpy.ListFields(fc)] for field in fields: for i in range(len(l)): if field == l[0]: for j in range(1,len(l)): with arcpy.da.UpdateCursor(fc, field) as cursor: for row in cursor: row[0] = l[j] print row cursor.updateRow(row) breakWhen i print row it seems to give desired result as shown below.

[1.0][2.0][3.0][4.0][5.0][7.0][8.0][None][None][None][None][None][None][None][None][None][None][u'3239'][u'2271'][u'2271'][u'2272'][u'55'][u'55'] [1][1][1][1][19][19][19][19]Observe the last 8 elements are the rows of Field 'TYP' as in python list. But they are not updated in table as shown below. WHY ?



May i am not using the "cursor.updateCursor(row)". kindly correct me.



أكثر...
 
أعلى