[GIS] Exporting list of Feature Classes to CSV using ArcPy and Python

arcpycsvexportpython

I am successfully using the follow script

import arcpy
from arcpy import env
import os
env.workspace = ("WORKSPACE")
fcList = arcpy.ListFeatureClasses()
print fcList

to export feature class names from a workspace.

I'd like to export the results to a CSV file (creating a simple one column list of Feature Class names); I've looked into the Python help guide but am struggling with the syntax and where to place the csv.writer and import csv functions.

How do I get the results to be written to a csv file?

Best Answer

Why not something like this:

import arcpy
from arcpy import env
import csv
import os
env.workspace = ("WORKSPACE")
fcList = arcpy.ListFeatureClasses()
with open('codes.csv', 'wb') as f:
     writer = csv.writer(f)
     writer.writerows(fcList)