HOW TO

Calculate the total number of fields in a feature class using Python ListFields() in ArcGIS Pro

Last Published: July 21, 2023

Summary

In ArcGIS Pro, the Get Count geoprocessing tool is used to calculate the total number of rows in an attribute table. However, this tool does not calculate the total number of columns, which represents the total number of fields in a feature class.

Providing a method to calculate this is helpful when there is a large number of attributes in a feature class. This is achieved using the Python ListFields() function.

An attribute table of a feature class.

Procedure

Follow the workflow below to calculate the total number of fields in a feature class using the Python ListFields() function.

  1. In ArcGIS Pro, on the Analysis tab, click the down arrow next to Python, and select Python window.
the Analysis tab and the drop-down menu of the Python button. Python Notebook and Python window are listed in the drop-down menu.
  1. In the Python window, in the prompt section, enter the Python ListFields() function as shown below. Refer to ArcGIS Pro: ListFields for more information.
import arcpy
fields = arcpy.ListFields('Feature Class Name')
print(len(fields))
Note:
Do not remove the single quotation marks enclosing the feature class name.

In this example, the feature class is Asia.

The Python window prompt section.
  1. Place the cursor at the end of the expression and press Enter twice on the keyboard. The image below shows the total number of fields for the Asia feature class is 8.
The Python window with the result after executing the ListField funtion.

Article ID: 000023096

Software:
  • ArcGIS Pro 2 8 x
  • ArcGIS Pro 2 7 x
  • ArcGIS Pro 2 x

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options