csv.py sucks for Decimal

Robert Kern robert.kern at gmail.com
Fri Apr 23 01:55:05 CEST 2010


On 4/22/10 6:23 PM, Phlip wrote:
> Pythonistas:
>
> 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
> just per-file.

Patches may be submitted here:

   http://bugs.python.org

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco




More information about the Python-list mailing list