[Csv] Re: First Cut at CSV PEP

Skip Montanaro skip at pobox.com
Thu Jan 30 03:21:51 CET 2003


    Skip> We could do like some of the DB API modules do and provide
    Skip> mappings which take the types of objects and see if a function
    Skip> exists to handle that type.

    Dave> I think this would make things too slow.  

Not in the typical case.  The typical case would be the null converter case.

    Dave> The Python core already has a convenience function for doing the
    Dave> necessary conversion; PyObject_Str().

This smacks of implicit type conversions to me, which has been the bane of
my interaction with Perl (via XML-RPC).  I still think we have no business
writing anything but strings, Unicode strings (encoded by codecs.open()),
ints and floats to CSV files.  Exceptions should be raised for anything
else, even None.  An empty field is "".

    Dave> If we are in a hurry we could document the existing low level
    Dave> writer behaviour which is to invoke PyObject_Str() for all
    Dave> non-string values except None.  None is translated to ''.

I really still dislike this whole None thing.  Whose use case is that
anyway? 

    Skip> Needless to say, our csv module should *not* do that.  Fried data,
    Skip> when accompanied by angry mobs, doesn't taste too good.  If the
    Skip> user specifies "never", I think an exception should be raised if
    Skip> no escape character is defined and fields containing the delimiter
    Skip> are encountered.

    Dave> Should the _csv parser should sanity check the combination of
    Dave> options in the constructor, or when told to write data which is
    Dave> broken?

I think only when a row is written which would create an ambiguous row.
Upon reading you have no real choice.  If there's an unescaped embedded
delimiter in an unquoted field, how is the reader object to know the user
doesn't want multiple fields?

    Dave> It is possible to define no quote or escape character but still
    Dave> write valid data.

    Dave>   1,2,3,4

Yup, and it should work okay, only barfing when there is an actual
ambiguity.

Skip

_______________________________________________
Csv mailing list
Csv at mail.mojam.com
http://manatee.mojam.com/mailman/listinfo/csv



More information about the Csv mailing list