string.split

Alex Martelli aleax at aleax.it
Wed Sep 5 03:52:02 EDT 2001


"Tom Harris" <TomH at optiscan.com> wrote in message
news:mailman.999670805.32745.python-list at python.org...
    ...
> set a literal string that is the seperator. How do I split on any or all
> occurrences of (for example) whitespace and a comma, without using
regexes.
> I mean string.split() must be able to do it anyway to achieve the default
> behaviour.

Nope -- look at objects/stringobject.c: string_split specialcases out
a call to split_whitespace when the splitter argument is missing or
None, and split_whitespace uses C's isspace to check for splitting.

I think it's a reasonable feature-request to wish for split to be
able to split on any one of several strings (e.g., make it callable
with several string arguments, or maybe with an argument that's a
sequence of strings), but feature-request it is -- it would need
additional code in stringobject.c.  So, you're advised to submit it
as a feature request to sourceforge.

Meanwhile, re.split does all you want, and it's not too bad, so
I suggest you use it anyway.


Alex






More information about the Python-list mailing list