CSV module: incorrectly parsed file.

Christopher Barrington-Leigh christopherbl at gmail.com
Mon Feb 18 03:09:12 CET 2008

Here is a file "test.csv"
1,"wer","tape 2"",5

I want to convert it to tab-separated without those silly quotes. Note
in the second line that a field is 'tape 2"' , ie two inches: there is
a double quote in the string.

When I use csv module to read this:

import sys
import csv
reader=csv.reader(open(sys.argv[1], "rb"))
for row in reader:
    outf.write('\t'.join([rr.strip() for rr in row]) +'\n')

it mangles it, messing up the double double-quote.
Can anyone help me? How do I use CSV to get it right?

More information about the Python-list mailing list