HOW TO

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

Last Published: July 20, 2023

Summary

In ArcGIS Desktop, 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 represent the total number of fields in a feature class.

Calculating the total number of fields is useful when there are a number of attributes in a feature class. The total can be derived using the Python ListFields() function.

Table showing a number of attributes

Procedure

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

  1. In ArcMap, click the Geoprocessing tab, and select Python to open the Python command window.
ArcMap Geoprocessing tab and window
  1. In the Python window, enter the Python ListFields() function.
print len(arcpy.ListFields(r"location of your feature class or shapefile","*")) 
Note: 
For more information on the function, refer to ArcMap: ListFields.

In this example, the following expression is used to count the fields in the Counties feature class:

print len(arcpy.ListFields(r"C:\Users\*****\Desktop\Data2\State.gdb\Counties","*"))
Fields in the Counties feature class
  1. Place the cursor at the end of the expression and press Enter. The image below shows the total number of fields for the Counties feature class is 5.
Total number of fields is 5

Article ID: 000022586

Software:
  • ArcMap

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