I'm writing a short script that iterates over a list of feature classes and sets values for a specific field ("Contour_Type"), based on the values in two other fields ("Type" and "Depression"). It seems my script does not pass the 'with arcpy.UpdateCursor(i) as cursor' line. I've searched for an answer, but can't find anything that pertains to my issue.
try:for i in inputfcs: arcpy.AddWarning("Populating new field values for:{0}".format(i)) with arcpy.UpdateCursor(i) as cursor: arcpy.AddWarning("Update Cursor set...") for row in cursor: if row.getValue("Type") == "Intermediate" and row.getValue("Depression") == "Yes": row.setValue("Contour_Type", "Intermediate_Depression") cursor.updateRow(row) elif row.getValue("Type") == "Index" and row.getValue("Depression") == "Yes": row.setValue("Contour_Type", "Index_Depression") cursor.updateRow(row) else: row.setValue("Contour_Type", row.getValue("Type")) cursor.updateRow(row)except: arcpy.AddError("Could not add new field values. Process will abort.") raise sys.exit()
أكثر...
try:for i in inputfcs: arcpy.AddWarning("Populating new field values for:{0}".format(i)) with arcpy.UpdateCursor(i) as cursor: arcpy.AddWarning("Update Cursor set...") for row in cursor: if row.getValue("Type") == "Intermediate" and row.getValue("Depression") == "Yes": row.setValue("Contour_Type", "Intermediate_Depression") cursor.updateRow(row) elif row.getValue("Type") == "Index" and row.getValue("Depression") == "Yes": row.setValue("Contour_Type", "Index_Depression") cursor.updateRow(row) else: row.setValue("Contour_Type", row.getValue("Type")) cursor.updateRow(row)except: arcpy.AddError("Could not add new field values. Process will abort.") raise sys.exit()
أكثر...