Bug or feature? 'abc'.split('') rejects empty separator

Paul Rubin phr-n2002a at nightsong.com
Sun Feb 10 16:44:13 EST 2002


Erik Max Francis <max at alcyone.com> writes:
> >  >>> 'abc'.split('')
> >  Traceback (most recent call last):
> >    File "<stdin>", line 1, in ?
> >  ValueError: empty separator
> > 
> > Wouldn't it make sense to return list('abc') ?
> 
> If that's what you really wanted, it would make far more sense to just
> use list directly rather than calling string.split on the string.  The
> error seems reasonable to me -- you shouldn't be using string.split if
> that's what you really want.

It seems to me like the principle that programs should be able to "do
nothing" gracefully.  The argument is that split should be the inverse
of join, even when the splitting string is empty.

Imagine if "a+0" raised an error.  You wouldn't say "just use 'a' instead".



More information about the Python-list mailing list