[Tutor] CSV to Excel

Susana Iraiis Delgado Rodriguez susana.delgado_s at utzmg.edu.mx
Fri Mar 11 21:59:20 CET 2011


Hello list!!

I'm trying to write a CSV file to work it with Excel. My python script is
working, the issue is: when I import the file from excel the data comes with
quotes at the beginnig and ending of the row. I don't want to have these
quotes. What is wrong with my code?

import os, csv
from osgeo import ogr,gdal,osr
from dbf import *
gdal.AllRegister()
file_list = []
folders = None
for root, folders, files in os.walk( "C:\\" ):
    file_list.extend(os.path.join(root,fi) for fi in files if
fi.endswith(".shp"))
writer = csv.writer(open('csv2.csv', "wb"))
campos = ['Ruta,Archivo,.prj']
writer.writerow(campos)
for row, filepath in enumerate(file_list, start=1):
    (ruta, filename) = os.path.split(filepath)
    n = os.path.splitext(filepath)
    p = n[0]+'.prj'
    if os.path.exists(p):
        aRow = [""+filepath+","+filename+",1"]
        writer.writerow(aRow)
    else:
        aRow1 = [""+filepath+","+filename+",0"]
        writer.writerow(aRow1)
print "El archivo esta listo"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110311/a54f5e32/attachment.html>


More information about the Tutor mailing list