import arcpy
import csv
import glob, os
os.chdir("C:\\path\\folder")
fieldsource = "C:\\path\\sampleshp.shp"
fields = [r.name for r in arcpy.ListFields(fieldsource)]
csv_out = "C:\\path\\table.csv"
with open(csv_out, "wb") as f:
wr = csv.writer(f)
wr.writerow(fields)
for file in glob.glob("*.shp"):
in_shp = "C:\\path\\folder\\" + file
with arcpy.da.SearchCursor(in_shp, fields) as cursor:
for row in cursor:
wr.writerow(row)
I have few thousand shapefiles with only a few rows in them. I want to export their table to a single csv file. The script works but it seems I have a character in some of the files that python(2.7) doesn't like:
Traceback (most recent call last): File "C:\path\folder\table.py", line 20, in wr.writerow(row) UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position 2: ordinal not in range(128)
How can I exclude/change the character that creates the issue?