I'm using matt wilkies' arcplus module https://gis.stackexchange.com/a/5943/16793 to export a list of feature classes within an SDE database to a text file. I've also written a tool to write field names to a csv file:
"""The source code of the tool.""" import arcpy, os, csv fclass = "SDEConnection\\"+Feature fieldnames = [f.name for f in arcpy.ListFields(fclass)] writepath = r"C:\Users\ME\Desktop\TableFields\\"+Feature+".csv" with open(writepath, "w") as output: writer = csv.writer(output, lineterminator='\n') for val in fieldnames: writer.writerow([val]) Ideally, I'd like to loop through the feature classes and fields and write a write file containing something like below:
Feature Class or Table-----------------------------------Fields
WELLS.WELL_DATA-------------------------------------WELL_KEY, SITEID, DEPTH, DIAMETER
I'm a little stumped on nesting the loops and formatting the output like this.
-----------EDIT-----------------------------------------------------------
Using the Walk method with a script like this
import os, arcpy, csv def inventory_data(workspace, datatypes): for path, path_names, data_names in arcpy.da.Walk( workspace, datatype=datatypes): for data_name in data_names: yield os.path.join(path, data_name) obtains a unicode string like "C:\Users\user\AppData\Roaming\Esri\Desktop10.2\ArcCatalog\Connection to oracle.sde\BASINS\BASINS.ONE"
while
fn = [f.name for f in arcpy.ListFields(fc)] print fn extracts a list
[u'FNODE_', u'TNODE_', u'LPOLY_', u'RPOLY_',]
My aim is to combine Walk with ListFields in a loop and write the FeatureClass with its accompanying fields (delimited) to a file.