import arcpy, csv fc = "E:\HUC2_DATA\HUC02\NewShapes\Result.gdb\HUC02Transect200m15pt" #input feature class rows = arcpy.SearchCursor(fc) csvFile = csv.writer(open("E:\HUC2_DATA\HUC02\NewShapes\HUC02Test.csv", 'wb')) #output csv fieldnames = [f.name for f in arcpy.ListFields(fc)] allRows = [] for row in rows: rowlist = [] for field in fieldnames: rowlist.append(row.getValue(field)) allRows.append(rowlist) csvFile.writerow(fieldnames) for row in allRows: csvFile.writerow(row)
Solved! Go to Solution.
import arcpy, csv fc = "E:\HUC2_DATA\HUC02\NewShapes\Result.gdb\HUC02Transect200m15pt" #input feature class rows = arcpy.SearchCursor(fc) fieldnames = [f.name for f in arcpy.ListFields(fc)] csvFile = csv.DictWriter(open("E:\HUC2_DATA\HUC02\NewShapes\HUC02Test.csv", 'wb'), fieldnames) #output csv allRows = [] for row in rows: rowlist = {} for field in fieldnames: rowlist['field'] = row.getValue(field)) allRows.append(rowlist) csvFile.writeheader() for row in allRows: csvFile.writerow(row)
import arcpy, csv fc = "E:\HUC2_DATA\HUC02\NewShapes\Result.gdb\HUC02Transect200m15pt" #input feature class rows = arcpy.SearchCursor(fc) fieldnames = [f.name for f in arcpy.ListFields(fc)] csvFile = csv.DictWriter(open("E:\HUC2_DATA\HUC02\NewShapes\HUC02Test.csv", 'wb'), fieldnames) #output csv allRows = [] for row in rows: rowlist = {} for field in fieldnames: rowlist['field'] = row.getValue(field)) allRows.append(rowlist) csvFile.writeheader() for row in allRows: csvFile.writerow(row)
csvFile = csv.DictWriter(open("E:\HUC2_DATA\HUC02\NewShapes\HUC02Test.csv", 'wb'), fieldnames)