TransWikia.com

Attribute Column Not Found [STATE_ID = Number] - ArcPy

Geographic Information Systems Asked by ProgrammerMan on June 25, 2021

Running a basic SearchCursor in ArcPy:

def PrintUniqueValues(fc,field):
    arcpy.env.workspace = os.path.dirname(fc)
    featurecount = {}
    CountDi = {}
    with arcpy.da.SearchCursor(fc, field) as cursor:
        for row in cursor:
            if not row[0] in CountDi.keys:
                CountDi[row[0]] = 1
            else:
                CountDi[row[0]] += 1
    for key in CountDi.keys():
        wp("   "+str(CountDi[key])+"-"+str(key))

Gives me this error, and I can’t find any documentation or reason as to why.

Traceback (most recent call last):
  File "C:/diff_feature_classes.py", line 97, in <module>
    PrintUniqueValues(inputFC1, "DATECREATED")
  File "C:/diff_feature_classes.py", line 35, in PrintUniqueValues
    for row in cursor:
RuntimeError: Attribute column not found [FeatureClass][STATE_ID = 14213]

2 Answers

The error message is saying that there is a problem with your lines,

with arcpy.da.SearchCursor(fc, field) as cursor:
    for row in cursor:

Specifically when it tries to iterate through rows after creating the cursor it crashes saying that it has a problem with your input variables.

It looks to me like you're passing a field=value with [STATE_ID = 14213] where it should just be [STATE_ID]. It's worth trying and seeing if that fixes anything. Or add some debugging printouts like arcpy.AddMessage(fc, field) or something like it to see what values you're plugging into that cursor.

Answered by Smasher on June 25, 2021

It turns out that "DATECREATED" didn't exist in the table as a field name (it was "CREATEDATE', and that error message (for me anyway) was a really nasty way of it erroring out because there wasn't a field with that name.

Check the name of the field, ensure it exists.

Answered by ProgrammerMan on June 25, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP