Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

How to Iterate over a list of fields and use an UpdataCursor to update the values?

$
0
0
I have multiple feature class that I performed analysis on and for each field that starts with a "t*" and is type "Double". I need to use a UpdateCursor to update the values within each of the following fields. I don't know how to use a list of fields within my UpdateCursor as the field that needs to be updated. In a previous python script that I used to carry out summary statistics I used a python list to summarise the fields that started with a "t*" and were of type "Double". I'm not sure how to combine the two to get the Update Cursor to replace the first field for each update. Any help would really be appreciated.

Code:

>>>import arcpy
... fc = r'E:\Projects\H109009\Calcs.gdb\Int_NLC_Quats_CommAgricMD'
... cursor = arcpy.da.UpdateCursor(fc,["t75c2","Shape_Area","MD_NLC_Area"])
... for row in cursor:
...    row[0] = (row[0]*(row[1]/row[2]*100))/100
...    cursor.updateRow(row)

Regards

Viewing all articles
Browse latest Browse all 2485

Trending Articles