[Python-ideas] str.split with empty separator

Raymond Hettinger raymond.hettinger at gmail.com
Fri Jul 30 04:16:50 CEST 2010


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.


Raymond 



More information about the Python-ideas mailing list