[Csv] Re: First Cut at CSV PEP
Skip Montanaro
skip at pobox.com
Thu Jan 30 15:51:03 CET 2003
Dave> The None thing and the implicit __str__ conversion is there in the
Dave> Object Craft parser to be compatible with the DB-API....
Hmmm... I've used MySQLdb and psycopg and don't recall my queries returning
None. (He furiously searches for None in PEP 249...) Ah, I see:
SQL NULL values are represented by the Python None singleton on input
and output.
I generally have always defined my fields to have defaults and usually also
declare them NOT NULL, so I wouldn't expect to see None in my query results.
Still, the current treatment of None doesn't successfully round-trip
("select * ...", dump to csv, load from csv, repopulate database). Do you
distinguish an empty field from a quoted field printed as ""? That is, are
these output rows different?
5.0,,"Mary, Mary, quite contrary"\r\n
5.0,"","Mary, Mary, quite contrary"\r\n
the former parsing into
[5.0, None, "Mary, Mary, quite contrary"]
and the latter into
[5.0, "", "Mary, Mary, quite contrary"]
?
Dave> Now without the implicit __str__ and conversion of None to '' we
Dave> would require a shirtload of code to do the same thing, only it
Dave> would be as slow as a slug on valium.
How about we let the user define how to handle None? I would always want
None's appearing in my data to raise and exception. You clearly have a use
case for automatically mapping to the empty string.
Skip
More information about the Csv
mailing list