AttributeError: DescribeData: Method fieldInfo does not exist

2822
2
Jump to solution
08-03-2018 08:15 AM
JustinBridwell2
Occasional Contributor II

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. Everytime 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)))

0 Kudos
1 Solution

Accepted Solutions
RandyBurton
MVP Alum

I use something like this to get field information:

arcpy.env.workspace = r"C:\Path\To\file.gdb"
fcList = arcpy.ListFeatureClasses()
for fc in fcList:
    print "FC: {}".format(fc)
    fields = arcpy.ListFields(fc)
    for f in fields:
        print "\t {}".format(f.name)
        # other options:
        # print f.baseName
        # print f.aliasName
        # print f.length
        # print f.domain
        # print f.type
        # print f.editable
        # print f.isNullable 
        # print f.required
        # print f.scale
        # print f.precision‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

For describe to have a fieldInfo method, the feature class would need to be made into a feature layer:

fcList = arcpy.ListFeatureClasses()
for fc in fcList:
    print "FeatureClass: {}".format(fc)
    fl = arcpy.MakeFeatureLayer_management(fc) # make it a layer
    desc = arcpy.Describe(fl)
    field_info = desc.fieldInfo
    for index in range(0, field_info.count):
        print "Field Name: {0}".format(field_info.getFieldName(index))
‍‍‍‍‍‍‍‍

View solution in original post

2 Replies
RandyBurton
MVP Alum

I use something like this to get field information:

arcpy.env.workspace = r"C:\Path\To\file.gdb"
fcList = arcpy.ListFeatureClasses()
for fc in fcList:
    print "FC: {}".format(fc)
    fields = arcpy.ListFields(fc)
    for f in fields:
        print "\t {}".format(f.name)
        # other options:
        # print f.baseName
        # print f.aliasName
        # print f.length
        # print f.domain
        # print f.type
        # print f.editable
        # print f.isNullable 
        # print f.required
        # print f.scale
        # print f.precision‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

For describe to have a fieldInfo method, the feature class would need to be made into a feature layer:

fcList = arcpy.ListFeatureClasses()
for fc in fcList:
    print "FeatureClass: {}".format(fc)
    fl = arcpy.MakeFeatureLayer_management(fc) # make it a layer
    desc = arcpy.Describe(fl)
    field_info = desc.fieldInfo
    for index in range(0, field_info.count):
        print "Field Name: {0}".format(field_info.getFieldName(index))
‍‍‍‍‍‍‍‍
JustinBridwell2
Occasional Contributor II

.ListFields was definitely the way to go. I didn't realize that Descibe.InfoFields was only for layers not features classes.

0 Kudos