AnsweredAssumed Answered

Save field names to a .txt file

Question asked by arsouzaesilva3 on Nov 26, 2019
Latest reply on Nov 26, 2019 by arsouzaesilva3

Hi,

 

how can i change this code to write to a file all field names of each feature class that exists in a geodatabase.

 

import arcpy
enviro = r"C:/EsriTraining/PYTH/Automate/"
arcpy.env.workspace = enviro +"{}".format("SanDiego.gdb")
field_list = arcpy.ListFields("MajorAttractions")
txtFile = open(enviro +"{}".format("Majorattractions.txt"),"w")
txtFile.write("MajorAttractions field information" + "\n")
txtFile.write("-------------------------------------" + "\n")
for field in field_list:
      line = "Name: {}, Type: {}, Length: {}\n".format(
            field.name, field.type, field.length)
      txtFile.write(line)
txtFile.close()

 

Thank´s

Outcomes