ArcGIS - how to get a count of the fields in a feature class

2088
7
Jump to solution
07-25-2019 09:58 AM
AaronCraig2
Occasional Contributor

Hello - I was just replying to a problem with jumping attribute tables and wanted to share my experiences. When describing the data, I was trying to count the number of fields (attributes) in a dataset, but can only see how this can be done manually or with code/sql/fme.


If there isn't already a place I can simply glance to get this information, I feel like this information is important to people doing GIS design work.

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
AdrianWelsh
MVP Honored Contributor

I know you mentioned not using scripting or coding but this quick Python bit worked well for me

In Pro in the Python module:

import arcpy
fields = arcpy.ListFields('Layer Name')
print(len(fields))‍‍‍‍‍‍

View solution in original post

7 Replies
AdrianWelsh
MVP Honored Contributor

Aaron,

This may be still manual but a little less manual. You could go to the Fields view in Pro and look at all the fields there without it jumping around too much (I mean, I hope it doesn't jump in this view):

https://pro.arcgis.com/en/pro-app/help/data/geodatabases/overview/create-modify-and-delete-fields.ht...

AdrianWelsh
MVP Honored Contributor

I know you mentioned not using scripting or coding but this quick Python bit worked well for me

In Pro in the Python module:

import arcpy
fields = arcpy.ListFields('Layer Name')
print(len(fields))‍‍‍‍‍‍
AaronCraig2
Occasional Contributor

Haha maybe I should have said I was against dev'ing my own code 😉 this is awesome, thank you very much

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Just be aware that len(arcpy.ListFields(dataset)) will return the count of all fields, including system-managed fields like OID, GlobalID, etc...  It may be that you are interested in all fields, but it may be you are just interested in user-defined fields.

JoshuaBixby
MVP Esteemed Contributor

Adrian Welsh‌, you might want to update Line 02 to be

fields = arcpy.ListFields(dataset)

As written, Line 02 implies you pass a field name to the ListFields function, which isn't the case.

AdrianWelsh
MVP Honored Contributor

Whoa whoops! I totally meant dataset and NOT field name, haha. I changed my post to say Layer Name (since that is what my little python script was looking for). 

Thanks for pointing that out!

And good point on how that will return all fields instead of just user-defined ones.

AaronCraig2
Occasional Contributor

No worries. Was able to get it to work. Cheers

0 Kudos