[Csv] PEP 305
Shawn Dyer
sdyer at dyermail.net
Wed Aug 20 21:40:39 CEST 2003
In studying the new CSV module, I find two problems, particularly in
interpreting csv files used for database import/export. Currently we use
our own csv parsing/writing utility, but would like to use the language
supported facility if possible.
1. When reading a field with adjacent delimiters (an empty field), your
code always maps that to an empty string. When interpreting DB output (at
least for DB2), an empty string is a pair of quotes. An empty field
represents NULL in the database and we parse that as the Python object
None (same result as from an SQL query). Using the csv module as is, an
empty string and None export identically. If this behavior were encoded
into the dialect, we could easily modify this behavior to suit our needs.
2. The other problem for my application, is the differentiation between
numeric data and strings of numbers in the csv file (this again is related
to DB2 import/export files). Our needs are to map anything with quotes in
the csv to a string (even if it is numeric). Anything without quotes
should map to a Python numeric type (or, as mentioned above, None when
adjacent delimiters appear). Of course, this would imply the possibility
of a ValueError when reading a csv. Again, it seems this behavior could be
parameterized out into the dialect.
Possibly both items could be addressed by a map_to_python_object
parameter.
If you are interested in including these modifications, I can try to come
up with a patch.
More information about the Csv
mailing list