Python CSV DictWriter Problems

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

  1. Is there a known-bug in csv.DictWriter? It is ignoring my attempts to
    specify a Dialect. It doesn't even error if you give it anything
    invalid. I can send it the registered string-name of the dialect, a
    string of gibberish, a dialect object instance, a dialect class
    object... it accepts all and ignores all.

    Take for example a default-created Dialect, excel-tab:

    Python 2.3.3 (#1, Apr 14 2004, 01:02:50)
    [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import csv
    >>> csv.list_dialects()

    ['excel-tab', 'excel']
    >>> csv.excel_tab.delimiter

    '\t'
    >>> a =

    csv.DictWriter(open('/root/quickbooks/testout.iif','w'),['a','b'],"excel-tab")

    >>> a.writer.dialect.delimiter

    ','
    >>> a =

    csv.DictWriter(open('/root/quickbooks/testout.iif','w'),['a','b'],csv.excel_tab())

    >>> a.writer.dialect.delimiter

    ','
    >>> a =

    csv.DictWriter(open('/root/quickbooks/testout.iif','w'),['a','b'],"no
    one is listening")
    >>> a.writer.dialect.delimiter

    ','
    >>> a =

    csv.DictWriter(open('/root/quickbooks/testout.iif','w'),['a','b'],csv.excel_tab)

    >>> a.writer.dialect.delimiter

    ','
    >>> a.writer.dialect = csv.excel_tab()

    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    TypeError: readonly attribute
    >>>


    Currently I have to go through and manually set each of the dialect's
    attributes individually, like so:
    >>> a.writer.dialect.delimiter = '\t'

    (etc.)
    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:
    643
    Michal Mikolajczyk
    Feb 13, 2004
  2. Skip Montanaro
    Replies:
    0
    Views:
    708
    Skip Montanaro
    Feb 13, 2004
  3. Gabriel Cooper

    Re: Python CSV DictWriter Problems

    Gabriel Cooper, May 3, 2004, in forum: Python
    Replies:
    0
    Views:
    936
    Gabriel Cooper
    May 3, 2004
  4. Tintin92
    Replies:
    1
    Views:
    1,694
    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:
    653
    Alan G Isaac
    Aug 14, 2009
Loading...

Share This Page