English

Problem: arcpy.ListFields fails to return values in ArcMap

Description

When using the arcpy.ListFields function in Python, no values are returned because the desired table or feature class is not found in ArcMap.
[O-Image]

Cause

The arcpy.ListFields function only returns feature class field aliases (geodatabase) and not layer field aliases defined in ArcMap. Feature classes without set aliases fail to return values when the function is called.

Additionally, values may fail to be returned if the file is not in the Table Of Contents in ArcMap and an incomplete file path is given to ListFields.

Solution or Workaround

  1. Open ArcMap. Right-click the desired table or feature class in the Table Of Contents.
  2. Select Properties to open the Layer Properties dialog box.
  3. Under the Source tab, check the table or feature class name set in the geodatabase. This ensures the correct database and feature class names are being used.
    [O-Image]


  4. Insert the path name for the feature class from the Layer Properties window into the arcpy.ListFields function.
    Note:
    Write the entire path, including any existing feature dataset containing the feature class.


    Code:
    import arcpy

    field_list = arcpy.ListFields(r"folder_location\gdb_name\FeatureDatasetName\FeatureClassName")

    for field in field_list:
    print("{0} is a type of {1} with a length of {2}"
    .format(field.name, field.type, field.length))

Related Information