csv.py sucks for Decimal
phlip2005 at gmail.com
Fri Apr 23 01:23:36 CEST 2010
This is not a question so much as registering a complaint.
When I use the CSV library, with QUOTE_NONNUMERIC, and when I pass in
a Decimal() object, I must convert it to a string. _Not_ a float,
because that might cause the rounding errors that Decimal() seeks to
avoid. (We use Decimal for Currency, naturally.)
Then product feed readers, who were written to ass-ume Excel output,
kack when they see quotes around a price field, such as "19.95".
I have fixed this by searching-and-replacing the quotes out of the
intermediate file. Please understand I am not asking after any such
low-level fix - and the search for an alternate CSV module, without
this bug, will indeed begin very soon! And, of course, we will switch
to XML wherever possible.
I'm pointing out that QUOTE_NONNUMERIC would work better with an
option to detect numeric-as-string, and absolve it. That would allow
Decimal() to do its job, unimpeded.
Also, the CSV format should set its configurations per-column, not
More information about the Python-list