Troubles with CSV file

Fuzzyman michael at foord.net
Fri May 14 11:08:30 EDT 2004


"Vladimir Ignatov" <vignatov at colorpilot.com> wrote in message news:<mailman.8.1084529146.4157.python-list at python.org>...
> Hello!
> 
> I have a big CSV file, which I must read and do some processing with it.
> Unfortunately I can't figure out how to use standard *csv* module in my
> situation. The problem is that some records look like:
> 
> ""read this, man"", 1
> 
> which should be decoded back into the:
> 
>     "read this, man"
>     1
> 
> ... which is look pretty "natural" for me. Instead I got a:
> 
>     read this
>       man""
>    1
> 
> output. In other words, csv reader does not understand using of "" here.
> Quick experiment show me that *csv* module (with default 'excel' dialect)
> expects something like
> 
>      """read this, man""", 1
> 
> in my situation  - quotes actually must be trippled. I don't understand this
> and can't figure out how to proceed with my CSV file. Maybe some
> *alternative* CSV parsers can help?  Any suggestions are welcomed.
> 
>     Vladimir Ignatov


I have written a very simple CSV parser which uses a simple function
'unquote' to unquote quoted elements.
It would be *very* simple to amend unquote to handle double-quoted
elements.

http://www.voidspace.org.uk/atlantibots/pythonutils.html

Regards,

Fuzzy



More information about the Python-list mailing list