1

I'm facing a difficulty to identify a feature by its name in a workspace and addfield to it.

import arcpy
arcpy.env.workspace ='C:\DATA_GEO\Bases de données\Vague 2\BOURRHA'
fcList = arcpy.ListFeatureClasses()
for feature in fcList:
    if feature.rfind("centroid")!=-1: #look for the feature having "centroid" in its name
        arcpy.AddField_management("fc", "ref_ID", "LONG", 9, "", "", "refcode", "NULLABLE", "REQUIRED")

But this is the error Python returns

Runtime error Traceback (most recent call last): File "", line 3, in
TypeError: 'NoneType' object is not iterable

How can I solve this?

1

It is telling you that fcList is empty. You can check this by adding print fcList. It could be that the path is not interpreted correctly. Try adding r in front of path: arcpy.env.workspace =r'C:\DATA_GEO\Bases de données\Vague 2\BOURRHA'.

See "What exactly do “u” and “r” string flags do, and what are raw string literals?"

You also need to change "fc" to feature in add field.

  • I followed your instructions (adding "r" to the workspace and replacing "fc" by "feature" and it crossed that step. It's just that I have a new error message Runtime error Traceback (most recent call last): File "<string>", line 6, in <module> File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\management.py", line 3246, in AddField raise e ExecuteError: ERROR 000732: Input Table: Dataset feature does not exist or is not supported – Gauss002 Jul 28 '18 at 15:29
  • @Gauss002 not "feature" it should be feature (no quotes) – BERA Jul 28 '18 at 15:33

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.