Trying to understand updateCursor() for python

I am using ArcMap 10.2.2. I am attempting to write a script that will cycle through the classes in a database and change the attribution of 1 row.

Is my variable "lyr" being recognized as the classes in the dataset?

When referencing an attribute to change, do you reference the alias or the actual name of the attribute?

Code sample:

import arcpy dataset = arcpy.GetParameterAsText(0) arcpy.env.worspace = dataset classList = arcpy.ListFeatureClasses() for lyr in classList: rows = arcpy.UpdateCursor(lyr) for row in rows: othField = row.getValue("OTH") if othField == "No Information": row.OTH = "noInformation" rows.updateRow(row) else: pass del row del rows

You reference the actual field name rather than an alias.

When debugging a script, I always hard code the paths to directories--once that is working, then add thearcpy.GetParameterAsText(0). Also, it is preferrable to wrap a cursor in awithstatement (documentation). Finally, thepassstatement is extraneous. Try the following:

import arcpy dataset = r'C:path	odataset' arcpy.env.workspace = dataset fcs = arcpy.ListFeatureClasses() for fc in fcs: with arcpy.da.UpdateCursor(fc, "OTH") as cursor: for row in cursor: if row[0] == "No Information": row[0] = "noInformation" cursor.updateRow(row)

Watch the video: How to Get Rid of Black Blinking Cursor (October 2021).