Skip to main content
2 of 3
added 48 characters in body
mdholl6188
  • 333
  • 1
  • 12

There are a couple things wrong with this code snippet. First, you don't need to specify a SearchCursor just to look through a table. The UpdateCursor has the ability to read row values and update through a single iteration. Secondly, when assigning a value to a row, you need to set the index of the field to the value (row[0] = row[0][:2] + ' pig') based on the index set in the cursor (line 2). Lastly, the UpdateCursor updates rows at a time after each iteration... meaning you set the values of each field, then update the entire row (cursor.updateRow(row)) specified in line 3.

import arcpy
with arcpy.da.UpdateCursor("SepticTankPermit layer",['pid','pidgis']) as cursor:
    for row in cursor:
        if row[0] in [None,'','NULL']:
            row[1] = row[1][:2]  #etc...
        elif row[1] in [None,'','NULL']:
            row[0] = row[0][:2] #etc...
        else:
            print "Row not updated..."
        cursor.updateRow(row)
del cursor 
mdholl6188
  • 333
  • 1
  • 12