[Tutor] CSV to Excel
Joel Goldstick
joel.goldstick at gmail.com
Fri Mar 11 22:13:32 CET 2011
On Fri, Mar 11, 2011 at 3:59 PM, Susana Iraiis Delgado Rodriguez <
susana.delgado_s at utzmg.edu.mx> wrote:
> 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"]
>
I think your problem is in the line above.
If you remove the extra quotes the problem goes away
>>> filepath = 'filepath'
>>> filename = 'filename'
>>> aRow = [filepath,filename,1]
>>> aRow
['filepath', 'filename', 1]
writer.writerow(aRow)
> else:
> aRow1 = [""+filepath+","+filename+",0"]
> writer.writerow(aRow1)
> print "El archivo esta listo"
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
--
Joel Goldstick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110311/47361ff9/attachment-0001.html>
More information about the Tutor
mailing list