[CSV] Re: First Cut at CSV PEP

Skip Montanaro skip at pobox.com
Wed Jan 29 03:30:23 CET 2003


    Skip> I'm not so sure this mapping None to "None" on output is such a
    Skip> good idea because it's not reversible in all situations and hurts
    Skip> portability to other systems (e.g., does Excel have a concept of
    Skip> None? what happens if you have a text field which just happens to
    Skip> contain "None"?).

    Dave> I think that None should always be written as a zero length field,
    Dave> and always read as the field value 'None'

I'm really skeptical of this.  There is just no equivalence between None and
''.  Right now using the Object Craft csv module, a blank field comes
through as an empty string.  I think that's the correct behavior.

    Skip> I think we need to limit the data which can be output to strings,
    Skip> Unicode strings (if we use an encoded stream), floats and ints.
    Skip> Anything else should raise TypeError.

    Dave> Is there any merit having the writer handling non-string data by
    Dave> producing an empty field for None, and the result of
    Dave> PyObject_Str() for all other values?

I'm not sure.  I'm inclined to not allow anything other than what I said
above.  Certainly, compound objects should raise exceptions.  I think of CSV
more like XML-RPC than Pyro.  We're trying to exchange data with as many
other languages and applications as possible, not create a new protocol for
exchanging data with other Python programs.  CSV is designed to represent
the numeric and string values in spreadsheets and databases.  Going too far
beyond that seems like out-of-scope to me, especially if this is to get into
2.3.  Remember, 2.3a1 is already out there!

    Dave> That raises another implementation issue.  If you export from
    Dave> Excel, does it always quote fields?  If not then the default
    Dave> dialect behaviour should not unconditionally quote fields.

Not in my limited experience.  It quotes only where necessary (fields
containing delimiters or starting with the quote character).

    Dave> We could/should support mandatoryquote as a writer option.

This is something Laurence Tratt's original CSV module did (his ASV module
probably does as well).  I used it all the time.  Gnumeric provides
"always", "as needed" and "never".  I don't know how you'd do "never"
without specifying an escape character.  I just tried "never" while saving
CSV data from Gnumeric.  It didn't escape embedded commas, so it effectively
toasted the data.  

Skip



More information about the Csv mailing list