I need to write a csv file that lists every record from an ID field across all feature classes in a gdb. The code I have written below does that fine, but I also need to write in the second column of the csv which feature class the record was found in.
I have been trying to create the cursor so that it also contains the fc name, then when I use writerow(row) both fields will be printed, but I think this is not a viable approach. Can anyone point me in the right direction? I'm using arcgis 10.2.2
arcpy.env.workspace = r'C:\Data.gdb' output = r'C:\test.csv' fcs = arcpy.ListFeatureClasses() fieldnames = ['PropID', 'Feature Class'] with open(output, 'wb') as f: csvwriter = csv.writer(f) csvwriter.writerow(fieldnames) for fc in fcs: with arcpy.da.SearchCursor(fc,'PropID','PropID IS NOT NULL') as cursor: for row in cursor: csvwriter.writerow(row) del row, cursor