[Python-Dev] string.split
Andreas Beyer
beyer at imb-jena.de
Fri Feb 20 07:07:15 EST 2004
The documentation of string.split() says:
"... The returned list will then have one more item than the number of
non-overlapping occurrences of the separator in the string. ..."
The behaviour of split with Python 2.3.3 is:
>>> '\tb'.split()
['b'] # Bug?
>>> '\tb'.split('\t')
['', 'b']
>>> 'a\t\tb'.split()
['a', 'b']
>>> 'a\t\tb'.split('\t')
['a', '', 'b']
>>>
I think there are different interpretations of what a separator is. That
is not necessarily a bug, because without stripping a new-line at the
end of the string would yield a non-intuitive result list. However, the
difference between split with and without the 'sep' argument should be
documented.
Andreas
More information about the Python-Dev
mailing list