# 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'
Solved! Go to Solution.
rows = arcpy.UpdateCursor(inshape) for row in rows: if row.getValue(field1) == 1: row.setValue(field2, "Definite") elif row.getValue(field1) == 2: row.setValue(field2, "Probable") rows.updateRow(row)
# Import arcpy module import arcpy from arcpy import env env.workspace = "C:\\avdata\\PythonTest\\testgdb.gbd\\" # Local variables: fc = "zilltogra" #input Feature class field1 = "PassNum" #field with test values field2 = "ReddStatus" #field to be calculated items = arcpy.ListFields(fc) print items ##cursor = arcpy.UpdateCursor(inshape) ##row = cursor.next() ##while row: ## if row.field1 == 1: ## row.field2 = "Definite" ## elif row.field1 == 2: ## row.field2 = "Probable" ## cursor.updaterow(row) ## row = cursor.next(1) rows = arcpy.UpdateCursor(fc) for row in rows: if row.field1 == 1: row.field2 = "Definite" elif row.field1 == 2: row.field2 = "Probable"
# Import arcpy module import arcpy from arcpy import env env.workspace = "C:\\avdata\\PythonTest\\" # Local variables: inshape = "zilltogra101013.shp" #input shapefile field1 = "PassNum" #field with test values field2 = "ReddStatus" #field to be calculated fields = ['PassNum', 'ReddStatus'] ##cursor = arcpy.da.UpdateCursor(inshape) ##row = cursor.next() ##while row: ## if row.field1 == 1: ## row.field2 = "Definite" ## elif row.field1 == 2: ## row.field2 = "Probable" ## cursor.updaterow(row) ## row = cursor.next(1) rows = arcpy.UpdateCursor(inshape) for row in rows: if row.field1 == 1: row.field2 = "Definite" elif row.field1 == 2: row.field2 = "Probable"
rows = arcpy.UpdateCursor(inshape) for row in rows: if row.getValue(field1) == 1: row.setValue(field2, "Definite") elif row.getValue(field1) == 2: row.setValue(field2, "Probable") rows.updateRow(row)
del row del rows