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

skip at pobox.com skip at pobox.com
Thu Dec 11 17:36:11 CET 2008

    Guido> Which of the two would you choose for all? The empty string is the
    Guido> only reasonable behavior for split-with-argument, it is the logical
    Guido> consequence of how it behaves when the string is not empty. E.g.
    Guido> "x:y".split(":") -> ["x", "y"], "x::y".split(":") -> ["x", "", "y"],
    Guido> ":".split(":") -> ["", ""]. OTOH split-on-whitespace doesn't behave
    Guido> this way; it extracts the non-empty non-whitespace-containing
    Guido> substrings.

In my feeble way of thinking I go from something which evaluates to false to
something which doesn't. It's almost like making matter out of empty space:

    bool("") -> False
    bool("".split()) -> False
    bool("".split("n")) -> True

    Guido> If anything it's wrong, it's that they share the same name. This
    Guido> wasn't always the case. Do you really want to go back to .split()
    Guido> and .splitfields(sep)?

That might be preferable.  The same method having such strikingly different
behavior throws me every time I try splitting a possibly empty string with a
non-whitespace character.  It's a relatively uncommon case.  Most of the
time when you split a string with a non-whitespace character I think you
know that the input can't be empty.


More information about the Python-ideas mailing list