[Python-ideas] This seems like a wart to me...

Stephen J. Turnbull turnbull at sk.tsukuba.ac.jp
Fri Dec 12 08:14:23 CET 2008


Carl Johnson writes:

 > what you meant was "I can't imagine new programmers wanting to go  
 > into the re module to learn how to do something like  
 > string.splitonchars." To which I say: Yes! I heartily agree! :-D

I don't understand this point of view at all.  True, regexps are a
complex subject, with an unfortunately large number of dialects.  Is
it the confusion of dialects problem, or do you really never use
regexps in any language?

Anyway, for this purpose you only have to learn one idiom, that

    longstring.splitonchars (["x", "y", "z"])

is spelled

    import re
    re.split ("[xyz]", longstring)

In fact, I personally would like to deprecate the with-argument
implementation of string.split(), and have

    def split (self, delimiter = None):
        if delimiters is None:
            return self.usual_magic_splitting ()
        else:
            import re
            return re.split (delimiter, self)

(of course, that's because that's precisely the way split-string works
in Emacs).

Then the idiom would be

    longstring.split ("[xyz]")

Would that work for you?




More information about the Python-ideas mailing list