Skip to content

Instantly share code, notes, and snippets.

@hwidlund
Last active May 4, 2016 21:28
Show Gist options
  • Select an option

  • Save hwidlund/47a7aa5f5862f19e9223e4cdb6594967 to your computer and use it in GitHub Desktop.

Select an option

Save hwidlund/47a7aa5f5862f19e9223e4cdb6594967 to your computer and use it in GitHub Desktop.
Snippets to work with feature class fields in Python and arcpy
import arcpy
featureClass = "c:/path/Geodatabase.gdb/fc"
# Get a list of field objects from a feature class
fcFields = arcpy.ListFields(featureClass)
# Print the field names, types and lengths using string formatting
for field in fcFields:
print("{0}: type = {1} length = {2}".format(field.name, field.type, field.length))
# Get a list of field names from a feature class using list comprehension
fieldNames = [field.name for field in arcpy.ListFields(featureClass)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment