[Python-Dev] New string method - splitquoted

Guido van Rossum guido at python.org
Thu May 18 17:11:31 CEST 2006


This is not an apropriate function to add as a string methods. There
are too many conventions for quoting and too many details to get
right. One method can't possibly handle them all without an enormous
number of weird options. It's better to figure out how to do this with
regexps or use some of the other approaches that have been suggested.
(Did anyone mention the csv module yet? It deals with this too.)

--Guido

On 5/17/06, Dave Cinege
<dcinege-mlists-dated-1148357217.fc23eb at psychosis.com> wrote:
> Very often....make that very very very very very very very very very often,
> I find myself processing text in python that  when .split()'ing a line, I'd
> like to exclude the split for a 'quoted' item...quoted because it contains
> whitespace or the sep char.
>
> For example:
>
> s = '      Chan: 11  SNR: 22  ESSID: "Spaced Out Wifi"  Enc: On'
>
> If I want to yank the essid in the above example, it's a pain. But with my new
> dandy split quoted method, we have a 3rd argument to .split() that we can
> spec the quote delimiter where no splitting will occur, and the quote char
> will be dropped:
>
>         s.split(None,-1,'"')[5]
>         'Spaced Out Wifi'
>
> Attached is a proof of concept patch against
> Python-2.4.1/Objects/stringobject.c  that implements this. It is limited to
> whitespace splitting only. (sep == None)
>
> As implemented the quote delimiter also doubles as an additional separator for
> the spliting out a substr.
>
> For example:
>         'There is"no whitespace before these"quotes'.split(None,-1,'"')
>         ['There', 'is', 'no whitespace before these', 'quotes']
>
> This is useful, but possibly better put into practice as a separate method??
>
> Comments please.
>
> Dave
>
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/guido%40python.org
>
>
>
>


-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list