Re: Python CSV DictWriter Problems

Discussion in 'Python' started by Gabriel Cooper, May 3, 2004.

  1. 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.
     
    Gabriel Cooper, May 3, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michal Mikolajczyk
    Replies:
    0
    Views:
    666
    Michal Mikolajczyk
    Feb 13, 2004
  2. Skip Montanaro
    Replies:
    0
    Views:
    729
    Skip Montanaro
    Feb 13, 2004
  3. Gabriel Cooper

    Python CSV DictWriter Problems

    Gabriel Cooper, May 3, 2004, in forum: Python
    Replies:
    0
    Views:
    2,049
    Gabriel Cooper
    May 3, 2004
  4. Tintin92
    Replies:
    1
    Views:
    1,729
    Andrew Thompson
    Feb 14, 2007
  5. Alan G Isaac

    csv.DictWriter.write_header()

    Alan G Isaac, Aug 12, 2009, in forum: Python
    Replies:
    5
    Views:
    664
    Alan G Isaac
    Aug 14, 2009
Loading...

Share This Page