New to Python. I'm trying to combine two scripts I found online that use the ListDatasets and ListFields tools. One loops through all the features of a geodatabase and writes the name of the feature dataset, feature class, and the number of features to a .csv file. To that one I would like to add the other that prints to the screen information about the attributes--name, type, and length. I would like all of this printed to a single .csv file like this:
The ListDatasets Script:
import arcpy
arcpy.env.workspace = "C:\Users\Redfish\Test.sde\Test.DBO.Structures\Test.DBO.HospitalBldg"
file = open("C:\Users\Redfish\Desktop\DatabaseDictionary.csv", "w")
file.write('Dataset, LayerName, NoOfRecords' + '\n')
for fds in arcpy.ListDatasets('*','feature') + ['']:
for fc in arcpy.ListFeatureClasses('*','',fds):
result = int(arcpy.GetCount_management(fc).getOutput(0))
file.write(fds + ', ' + fc + ', ' + str(result) + '\n')
file.close()
The ListFields Script
import arcpy
arcpy.env.workspace = "C:\Users\Redfish\Test.sde\Test.DBO.Structures\Test.DBO.HospitalBldg"
fields = arcpy.ListFields("C:\Users\Redfish\Test.sde\Test.DBO.Structures\Test.DBO.HospitalBldg")
for field in fields:
print("{0}\{1}\{2}"
.format(field.name, field.type, field.length))