AnsweredAssumed Answered

da.UpDateCursor to conditionally calculate a field based on test of another field

Question asked by huffmanp on May 23, 2014
Latest reply on May 28, 2014 by huffmanp
I was testing out arcpy.da.UpdateCursor to calculate a field based on another fields value.  My script runs without error, but doesn't seem to make any changes in the shapefile.  I tried adding the line overwriteOutput = "True" but that didn't work.  The print line I added for debugging shows the correct values for ReddStatus or row[1], but they don't get saved in the output.

 # Import arcpy module import arcpy from arcpy import env env.workspace = "C:\\avdata\\PythonTest\\" arcpy.env.overwriteOutput = "True"  # Local variables: inshape = "zilltogra101013.shp" #input shapefile field1 = "PassNum" #field with test values field2 = "ReddStatus" #field to be calculated fields = ['PassNum', 'ReddStatus']       with arcpy.da.UpdateCursor(inshape, fields) as cursor:     for row in cursor:                  if row[0] == 1:            row[1] = "Definite"         elif row[0] == 2:            row[1] = "Probable"         print row[0],row[1], '\n'

Outcomes