Skip to main content
For the program to execute as required you'd have to concatenate the missing information from the field that contained it. Instead of recalcuating the existing field.
Source Link

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[1] = row[0][:2] + ' pig'pid') based on the index set in the cursor (line 2). Lastly, the UpdateCursor updates rows one 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[0] = row[1][:2]  #etc...
        elif row[1] in [None,'','NULL']:
            row[0]row[1] = row[0][:2] #etc...
        else:
            print "Row not updated..."
        cursor.updateRow(row)
del cursor 

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 

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[1] = row[0][:2] + ' pid') based on the index set in the cursor (line 2). Lastly, the UpdateCursor updates rows one 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[0] = row[1][:2]  #etc...
        elif row[1] in [None,'','NULL']:
            row[1] = row[0][:2] #etc...
        else:
            print "Row not updated..."
        cursor.updateRow(row)
del cursor 
added 48 characters in body
Source Link
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 rowfield 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 

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 row to the value (row[0] = row[0][:2] + ' pig'). 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 

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 
Source Link
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 row to the value (row[0] = row[0][:2] + ' pig'). 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