Skip to main content
edited tags
Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345
edited tags
Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345
Source Link
a11
  • 950
  • 11
  • 25

More Pythonic way to loop through UpdateCursor?

I have several sets of fields to populate based on other fields. The code below works, but I am wondering if there is a more Pythonic way to march through the i,j pairs? (Actual fieldnames are not this simple.)

i = ['FieldA1', 'FieldB1', 'FieldC1', 'FieldD1']
j = ['FieldA2', 'FieldB2', 'FieldC2', 'FieldD2']

if len(i) != len(j):
    arcpy.AddMessage("Error - i & j are not the same length")
    sys.exit()

for n in range(len(i)):
    fields = [i[n], j[n]]
    with arcpy.da.UpdateCursor(mySHP, fields) as cursor:
        for row in cursor:
            val = row[0]
            if float(val) == -999:
                row[1] = -999
            else:
                row[1] = float(val) / 100
            cursor.updateRow(row)