Trying to fix Invalid CSV File

Ryan Rosario uclamathguy at
Mon Aug 4 10:15:31 CEST 2008

On Aug 4, 1:01 am, John Machin <sjmac... at> wrote:
> On Aug 4, 5:49 pm, Ryan Rosario <uclamath... at> wrote:
> > Thanks Emile! Works almost perfectly, but is there some way I can
> > adapt this to quote fields that contain a comma in them?
> You originally said "I have a very large CSV file that contains double
> quoted fields (since they contain commas)". Are you now saying  that
> if a field contained a comma, you didn't wrap the field in quotes? Or
> is this a separate question unrelated to your original problem?

I enclosed all text fields within quotes. The problem is that I have
quotes embedded inside those text fields as well and I did not double/
escape them. Emile's snippet takes care of the escaping but it strips
the outer quotes from the text fields and if there are commas inside
the text field, the field is split into multiple fields. Of course, it
is possible that I am not using the snippet correctly I suppose.

More information about the Python-list mailing list