CSV: minimalquoting and skipinitialspace,

Discussion in 'Python' started by Martin Bless, May 19, 2004.

  1. Martin Bless

    Martin Bless Guest

    Currently QUOTE_MINIMAL in the standard module CSV only reacts to
    "delimiter" and "quotechar". From the documentation:

    Currently:
    """
    QUOTE_MINIMAL
    Instructs writer objects to only quote those fields which contain the
    current delimiter or begin with the current quotechar.
    """

    In my opinion there should be a way to turn on quoting as well for
    those fields, that start with white space characters if the dialect
    specifies

    dialect.skipinitialspace = False

    I wouldn't mind a change leading to this variant:

    Proposal:
    """
    QUOTE_MINIMAL
    Instructs writer objects to only quote those fields which contain the
    current delimiter or begin with the current quotechar or start
    with a [blank | white space character] if the dialect specifies
    skipinitialspace=False.
    """

    What do you think?

    MB - Martin Bless
    Martin Bless, May 19, 2004
    #1
    1. Advertising

  2. Martin> Proposal:

    Martin> QUOTE_MINIMAL
    Martin> Instructs writer objects to only quote those fields which
    Martin> contain the current delimiter or begin with the current
    Martin> quotechar or start with a [blank | white space character] if the
    Martin> dialect specifies skipinitialspace=False.

    Martin> What do you think?

    It's an idea with merit. Can you post a feature request to the Python
    project on SF? Even better would be a patch that implements the idea. ;-)

    Skip
    Skip Montanaro, May 19, 2004
    #2
    1. Advertising

  3. Martin Bless

    Martin Bless Guest

    [Skip Montanaro <>]

    >Can you post a feature request to the Python
    >project on SF?


    Ok, I think I can do that. Having thought it over I'd love to see this
    logic:

    # pseudo code, untested
    if dialect.quoteminimal:
    quote_the_field = False
    if dialect.delimiter in field:
    quote_the_field = True
    elif dialect.separator in field:
    quote_the_field = True

    # NEW: do quoting if field starts OR ends with a space or a tab
    elif field[:1] in " \t" or field[-1:] in " \t":
    quote_the_field = True


    >Even better would be a patch that implements the idea. ;-)


    Too bad, I can't. I had a look at it: the crucial parts are in the
    c-code. That's too far for me in the moment ...

    MB - Martin Bless
    Martin Bless, May 19, 2004
    #3
    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:
    628
    Michal Mikolajczyk
    Feb 13, 2004
  2. Skip Montanaro
    Replies:
    0
    Views:
    691
    Skip Montanaro
    Feb 13, 2004
  3. Tintin92
    Replies:
    1
    Views:
    1,672
    Andrew Thompson
    Feb 14, 2007
  4. jliu66
    Replies:
    0
    Views:
    492
    jliu66
    Oct 19, 2007
  5. Sacha Rook

    csv read clean up and write out to csv

    Sacha Rook, Nov 2, 2012, in forum: Python
    Replies:
    2
    Views:
    199
    Hans Mulder
    Nov 2, 2012
Loading...

Share This Page