[Python-ideas] str.split() oddness

Bruce Leban bruce at leapyear.org
Mon Mar 7 09:48:48 CET 2011

On Sun, Mar 6, 2011 at 7:27 PM, Guido van Rossum <guido at python.org> wrote:

> Well, I'm sorry, but this is not going to change ... The cost of change is
> just too high,
> so we'll just have to live with the current behavior (and we might as
> well accept that it's solid instead of trying to fight it).
Completely agree.

It's interesting that the one thing that annoys me about string.split hasn't
been mentioned here. I'm not bothered by the inconsistency in handling of
the degenerate cases because frequently I need code to handle the degenerate
case specially anyway.

What *does* annoy me is the inconsistency of what the count parameter means
between different languages. That is str.split(delimiter, count) means
different things in different languages:

Python/Javascript = max number of splits
Java/C#/Ruby = max number of results

Obviously, it would break things badly to switch from one to the other (in
any language). An alternative would be first changing to:

    str.split(sep, maxsplits=None)

and modify pylint to complain if maxsplits is used as a non-keyword
argument. Eventually, change to

    str.split(sep, deprecated=None, maxsplits=None)

where this throws an exception if deprecated is not None. This would also
open up having maxresults keyword if it's desirable to allow either variant.

--- Bruce
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20110307/4b54d754/attachment.html>

More information about the Python-ideas mailing list