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
for f in arcpy.Describe(<TheFeatureClass>).fields: if f.name == TheFieldName: FIELD_ALIAS = f.aliasName
<SPAN class="comment token"># This is essentially the line you'll need</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">(</SPAN>f<SPAN class="punctuation token">.</SPAN>name<SPAN class="punctuation token">,</SPAN> f<SPAN class="punctuation token">.</SPAN>aliasName<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> f <SPAN class="keyword token">in</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Describe<SPAN class="punctuation token">(</SPAN><SPAN class="operator token"><</SPAN>PathToTable<SPAN class="operator token">></SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>fields<SPAN class="punctuation token">]</SPAN> <SPAN class="comment token"># This is an example of a way to use it</SPAN> <SPAN class="keyword token">import</SPAN> arcpy <SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Name,Alias"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> item <SPAN class="keyword token">in</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">(</SPAN>f<SPAN class="punctuation token">.</SPAN>name<SPAN class="punctuation token">,</SPAN> f<SPAN class="punctuation token">.</SPAN>aliasName<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> f <SPAN class="keyword token">in</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Describe<SPAN class="punctuation token">(</SPAN><SPAN class="operator token"><</SPAN>PathToTable<SPAN class="operator token">></SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>fields<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">","</SPAN><SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>item<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="string token">""" The above section would output something like Name,Alias OBJECTID,OBJECTID Shape,Shape AREANAME,AREA NAME POP2000, POP 2000 """</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
You can also use ListFields to access the fields.
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.
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.