How can I export a file geodatabase to csv table using python running a script from inside a map document.
Got the following code from Mathew Coyle off this forum and ran it but it did not work for me.
Other ideas?
Got the following code from Mathew Coyle off this forum and ran it but it did not work for me.
Other ideas?
Code:
import arcpy
from os import path as p
fc = "C:\\Test\\Test.gdb\\Test1"
CSVFile = "C:\\Test\\Test1"
def TableToCSV(fc,CSVFile):
fields = [f.name for f in arcpy.ListFields(fc) if f.type <> 'Geometry']
with open(CSVFile, 'w') as f:
f.write(','.join(fields)+'\n') #csv headers
with arcpy.da.SearchCursor(fc, fields) as cursor:
for row in cursor:
f.write(','.join([str(r) for r in row])+'\n')
print 'Created %s Successfully' %p.basename(CSVFile)