Seperating CSV rows into new, seperate files

Waldemar Osuch osuchw at ecn.ab.ca
Sun Aug 15 18:29:27 EDT 2004


TonyB wrote:
> In any case, it appears
> that the new files have some sort of additional line terminator that
> creates a blank row in the outputted file making the importing of the
> list impossible.   

When writing to a file using csv.writer on Windows open the file in 
binary format.

> row[SECTION])
>    fileobj = file(filename, 'a')
>    newfile = csv.writer(fileobj)
>    newfile.writerow(row)
>    fileobj.close() 
so
fileobj = file(filename, 'a')
becomes
fileobj = file(filename, 'ab')

That should fix it.

Waldek



More information about the Python-list mailing list