>>>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)
base_list = ["Shape_Area","MD_NLC_Area"] f_list = [f.name for f in arcpy.ListFields(fc, 't*', 'DOUBLE')] final_list = f_list + base_list cursor = arcpy.da.UpdateCursor(fc, final_list)
t_field = arcpy.ListFields(fc, 't*', 'DOUBLE')[0].name
field_list = ['t75c', 'SHAPE@AREA', 'MD_NLC_Area'] t_list = [t for t in field_list if t.startswith('t')] with arcpy.da.UpdateCursor(fc, field_list) as cursor: for row in cursor: for index, field in enumerate(t_list): row[index] = (row[index]*(row[-2]/row[-1]*100))/100 cursor.updateRow(row)
import arcpy ... fc = r'E:\Projects\H109009\Calcs.gdb\Int_NLC_Quats_CommAgricMD' ... f_list = [f.name for f in arcpy.ListFields(fc, "t*", "Double")] ... field_list = f_list + ["SHAPE@AREA","MD_NLC_Area"] ... cursor = arcpy.da.UpdateCursor(fc,field_list) ... field_count = len(f_list) ... for row in cursor: ... shape_area = row[-2] ... md_nlc_area = row[-1] ... for index in xrange(field_count): ... row[index] = row[index]*(shape_area/md_nlc_area*100)/100 ... cursor.updateRow(row)
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.>>>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