[Python-ideas] str.split with empty separator
python at mrabarnett.plus.com
Fri Jul 30 04:41:35 CEST 2010
Raymond Hettinger wrote:
> On Jul 29, 2010, at 5:33 PM, Greg Ewing wrote:
>> Alexandre Conrad wrote:
>>> What if str.split could take an empty separator?
> I propose that the semantics of str.split() never be changed.
> It has been around for a long time and has a complex set of behaviors
> that people have come to rely on. For years, we've answered arcane
> questions about it and have made multiple revisions to the docs in a
> never ending quest to precisely describe exactly what it does without
> just showing the C underlying code. Accordingly, existing uses depend
> mainly on what-it-does-as-implemented and less on the various ways
> it has been documented over the years.
> Almost any change to str.split() would either complexify the explanation
> of what it does or would change the behavior in a way the would
> break somebody's code (perhaps in a subtle ways that are hard to detect).
> In my opinion, str.split() should never be touched again.
> Instead, it may be worthwhile to develop new splitters
> with precise semantics aimed at specific use cases.
Does it really have a complex set of behaviours? The only (possibly)
surprising behaviour for me is when it splits on whitespace (ie, passing
it None as the separator). I find it very easy to understand. Or perhaps
I'm just smarter than I thought! :-)
More information about the Python-ideas