csv.py sucks for Decimal

Jerry Hill malaclypse2 at gmail.com
Thu Apr 22 21:15:45 EDT 2010

On Thu, Apr 22, 2010 at 8:03 PM, MRAB <python at mrabarnett.plus.com> wrote:
> It might be a stupid question, but have you tried passing in the
> Decimal() object itself?

MRAB's suggestion works for me in python 3.1.2:

import csv, io
from decimal import Decimal

d = Decimal("10.00")
o = io.StringIO()
w = csv.writer(o, quoting=csv.QUOTE_NONNUMERIC)

w.writerow([10, 10.00, d, "10"])



That's an int, a float, a Decimal and a string, all of which appear to
be formatted as I would expect.


More information about the Python-list mailing list