Getting field name and alias list from data set?

3726
4
09-14-2016 01:28 PM
GareySmiley
New Contributor III

Is there a script that will dump the field names along with the field alias. I'm looking to get something like the following dumped for a data set.

Field, Alias

TOTPOP_CY, 2015 Total Population

HHPOP_CY, 2015 Population in Households

4 Replies
BrittneyWhite1
Esri Contributor

You would use the arcpy Describe function. You can then access the fields property which returns a list of Field objects that you can iterate through to get the aliasName and baseName properties.

BrittneyWhite1
Esri Contributor

You can also use ListFields to access the fields.

FreddieGibson
Regular Contributor II
# This is essentially the line you'll need
[(f.name, f.aliasName) for f in arcpy.Describe(<PathToTable>).fields]

# This is an example of a way to use it
import arcpy
print("Name,Alias")
for item in [(f.name, f.aliasName) for f in arcpy.Describe(<PathToTable>).fields]:
    print(",".join(item))

"""
The above section would output something like

Name,Alias
OBJECTID,OBJECTID
Shape,Shape
AREANAME,AREA NAME
POP2000, POP 2000
"""
LeandraGordon
Occasional Contributor II
for f in arcpy.Describe(<TheFeatureClass>).fields:
if f.name == TheFieldName:
FIELD_ALIAS = f.aliasName
0 Kudos