Thursday, 23 March 2017

python - arcpy.da.UpdateCursor - How to update last column from Field Name List?


examples:



for field in arcpy.ListFields(fc):
if field.name != 'Hi':
arcpy.AddField_management(fc, 'Hi', 'FLOAT')
else:
print "kolona Hi vec postoji"

with arcpy.da.UpdateCursor(fc, (fieldNameList)) as cursor:

for row in cursor:


hi = sum(np.array([row[i]/(sum([row[i] for i in range(len(fieldNameList))])) for i in range(len(fieldNameList))])**2)
row[14] = hi # row[LAST] = hi ?????

cursor.updateRow(row)

del row
del cursor

That instead of row[14] use the last column of the defined list? examples:


row[last] = hi


Answer



Try the last element list selector used in Python:


row[-1] = hi

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...