Skip to content

Instantly share code, notes, and snippets.

@NPS-ARCN-CAKN
Last active August 29, 2015 14:19
Show Gist options
  • Save NPS-ARCN-CAKN/c7c91e060665e1c1e5b2 to your computer and use it in GitHub Desktop.
Save NPS-ARCN-CAKN/c7c91e060665e1c1e5b2 to your computer and use it in GitHub Desktop.
Python: Loop through a FeatureClass' column names
import arcpy
fc = "C:/Work/VitalSigns/ARCN-CAKN Dall Sheep/Data/LegacySurveyUnits/ARCN_Subunits_Sheep_WGS84.shp"
fieldsList = arcpy.ListFields(fc) #get the fields
fields = [] # create an empty list
# loop through the fields and add the columns to the list, change the Shape column (containing geometry) into a token,
for field in fieldsList:
if field.name == "Shape":
fields.append("Shape@")
else:
fields.append(field.name)
# loop through the fields and output them
i = 0
for field in fieldsList:
print field.name + " = row[" + str(i) + "]"
i = i + 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment