using string.splitfields
M.-A. Lemburg
mal at lemburg.com
Mon Oct 11 17:10:51 EDT 1999
Fredrik Lundh wrote:
>
> Thomas Weholt <u970130 at studbo.hit.no> wrote:
> > Just wondering how I could use more field-separators when I use the
> > string.splitfield method.
>
> you can't. string.split can only
> deal with a single separator.
>
> (string.splitfield is obsolete, btw.
> use string.split instead).
>
> in this case, you can use
> re.split instead:
>
> import re
> print re.split("[.+!]", "this.is+a!string")
> ## ['this', 'is', 'a', 'string']
>
> </F>
>
> coming soon:
> http://www.pythonware.com/people/fredrik/librarybook.htm
Or check out setsplit() in mxTextTools (see Python Pages below).
>>> import TextTools
>>> print TextTools.setsplit("this.is+a!string",TextTools.set(".+!"))
['this', 'is', 'a', 'string']
It's *much* faster than the re approach in case you care.
--
Marc-Andre Lemburg
______________________________________________________________________
Y2000: 81 days left
Business: http://www.lemburg.com/
Python Pages: http://www.lemburg.com/python/
More information about the Python-list
mailing list