csv module and None values

JKPeck jkpeck at gmail.com
Mon Aug 24 15:55:31 EDT 2009


On Aug 24, 11:30 am, JKPeck <jkp... at gmail.com> wrote:
> I'm trying to get the csv module (Python 2.6) to write data records
> like Excel.  The excel dialect isn't doing it.  The problem is in
> writing None values.  I want them to result in just sequential commas
> - ,, but csv treats None specially, as the doc says,
>
> "To make it as easy as possible to interface with modules which
> implement the DB API, the value None is written as the empty string."
>
> I need strings to be quoted but not None values.  Is there any way to
> get around this special None treatment?
>
> TIA,
> Jon Peck

Solved the problem myself by giving a writer class to csv.writer that
looks for sentinel markers inserted in place of None and wipes them
out before writing to a file.  Pretty ugly, but it works.

Regards,
Jon Peck



More information about the Python-list mailing list