Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Export file geodatabase table to scv file

$
0
0
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?

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)


Viewing all articles
Browse latest Browse all 2485

Trending Articles