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"
del row
del rows
  • 1
    Are you getting an error? You should use the newer arcpy.da.UpdateCursor resources.arcgis.com/en/help/main/10.2/018w/… – user2856 Oct 31 '15 at 21:13
  • Yes, thanks. I was informed of this by a coworker as well. I would never have figured this out had it not been for you guys. – Josh Nov 6 '15 at 5:54

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 the arcpy.GetParameterAsText(0). Also, it is preferrable to wrap a cursor in a with statement (documentation). Finally, the pass statement is extraneous. Try the following:

import arcpy

dataset = r'C:\path\to\dataset'
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"
| improve this answer | |
  • There's a typo when setting the workspace: you're missing a 'k' (arcpy.env.workspace). – Ali Oct 31 '15 at 23:52
  • @SIslam - it's not my question. – Ali Nov 2 '15 at 9:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.