0

I have a script that looks at feature class inside a .gdb and prints some simple information about the attributes field. Note- these is actually only one feature class in the .gdb. I want use the arcpy.Describe method with fieldInfo. Every time the script gets to the line field_info = desc.fieldInfo, it throws the error AttributeError: DescribeData: Method fieldInfo does not exist. My feature class definitely has an attribute table with fields.

What is the problem here; why is this error being thrown and how can I fix it?

My end goal is to just get a list of the field names in my feature class attributes table:

import arcpy, sys, os

arcpy.env.workspace = r"C:/Workspace/Sandbox/MapChangeProject/data/Alabama.gdb"

fcList = arcpy.ListFeatureClasses()
for fc in fcList:
    print("FeatureClass: {}").format(fc)
    desc = arcpy.Describe(fc)

    field_info = desc.fieldInfo
    for index in range(0, field_info.count):
        print("Field Name: {0}".format(field_info.getFieldName(index)))
1

From ArcGIS Documentation:

FieldInfo Summary: Provides field info methods and properties for layer and table views.

Does not work on GDBs or FCs straight up. Need to convert to a FeatureLayer first.

I would suggest using arcpy.ListFields instead. There are direct GDB methods that you can use instead. I've never used the Describe stuff before.

4
  • Ah, well...that explains it. I'm really just looking at the tabular data and will probably want to keep it in the GDB at this point. What GDB methods are you referring to? DO you have a link? – gwydion93 Aug 3 '18 at 17:04
  • arcpy.ListFields() returns a list of field objects. Each field object has properties .name, .type, .length, etc. (see here: pro.arcgis.com/en/pro-app/arcpy/classes/field.htm). You can also use search cursors to search through your table very quickly for specific values in the table (see here: pro.arcgis.com/en/pro-app/arcpy/data-access/…) – Jvhowube Aug 3 '18 at 17:09
  • One additional question: I just did the following: fields = arcpy.ListFields(fc), then print(fields). It listed them but as [<Field object at 0x67ce790[0x55d6680]>, <Field object at 0x67ce6f0[0x55d6500]>,...]. How do fix that? – gwydion93 Aug 3 '18 at 17:12
  • That's because it's returning field objects. You need to call for the specific property of the field object (for instance f.name will return the names). for f in fields: print f.name – Jvhowube Aug 3 '18 at 17:13

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.