This should be simple but I've spent days trying everything to get it to work. I need to update a field in a layer based on two other fields. I can't even get it to update based on one field. Could someone please tell me whats wrong. So in this script I want to be classifying the outfield as "poor" if the infield is "Sandy". I will also have another field of numbers (and infield2 = "10").
rows = arcpy.UpdateCursor(infc) #this is my feature layer
for row in rows:
if row.getValue(Infield1) == "Sandy":
row.setValue(Outfield, "poor")
else:
row.setValue(Outfield, "none")
rows.updateRow(row)
del rows
Thanks for all the answers. The script only works if written like this: I did not want to name the field names though, but at least it works.
The only way I could do a range 5 - 10 was to put > 5 and <10 (see line 23)
for row in rows:
if row.getValue("Texture") == "Sandy" and row.getValue("Humus") < 10:
row.setValue("Richness", "poor")
elif row.getValue("Texture") == "Sandy" and row.getValue("Humus") > 10:
row.setValue("Richness", "medium")
elif row.getValue("Texture") == "Sandy-Clay" and row.getValue("Humus") < 5:
row.setValue("Richness", "poor")
elif row.getValue("Texture") == "Sandy-Clay" and row.getValue("Humus") >= 5 and row.getValue("Humus") <= 10:
row.setValue("Richness", "medium")
elif row.getValue("Texture") == "Sandy-Clay" and row.getValue("Humus") > 10:
row.setValue("Richness", "rich")
elif row.getValue("Texture") == "Clay" and row.getValue("Humus") < 5:
row.setValue("Richness", "poor")
elif row.getValue("Texture") == "Clay" and row.getValue("Humus") > 5:
row.setValue("Richness", "rich")
else:
row.setValue("Richness", "unclassified")
rows.updateRow(row)
del rows, row