CSV: minimalquoting and skipinitialspace,

M

Martin Bless

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
 
S

Skip Montanaro

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
 
M

Martin Bless

[Skip Montanaro said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top