Python CSV DictWriter Problems
Gabriel Cooper
gabriel.cooper at mediapulse.com
Mon May 3 17:37:13 EDT 2004
Skip Montanaro wrote:
> Gabriel> Is there a known-bug in csv.DictWriter? It is ignoring my
> Gabriel> attempts to specify a Dialect. It doesn't even error if you
> Gabriel> give it anything invalid. I can send it the registered
> Gabriel> string-name of the dialect, a string of gibberish, a dialect
> Gabriel> object instance, a dialect class object... it accepts all and
> Gabriel> ignores all.
>
>Fixed in CVS I believe. I will check when I get a chance (there doesn't
>seem to be a test case for this), but you might try grabbing the DictWriter
>class from the csv.py that's in CVS.
>
>
Bah, it turns out I was a goofball. I forgot that there were two
parameters between the last required param and the dialact parameter.
Basically the function definition looks like this:
*DictWriter*(csvfile, fieldnames[, restval=""[, extrasaction=|'raise'|[,
dialect=|'excel'|[, fmtparam]]]])
and I did this:
x = DictWriter(file, fields, dialect)
when I actually had to do either:
x = DictWriter(file, fields, None, None, dialect)
or
x = DictWriter(file, fields, dialect=dialect)
Whoops. I ignored the two parameters 'restval' and 'extrasaction'.
The worst part is how much time I spent looking at that and simply
didn't see it. Tsk Tsk.
Gabriel.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20040503/069b98ea/attachment.html>
More information about the Python-list
mailing list