Message 56026 - Python tracker (original) (raw)
I quoted str.split docs:
- http://docs.python.org/lib/string-methods.html
- http://docs.python.org/dev/library/stdtypes.html
- http://docs.python.org/dev/3.0/library/stdtypes.html
string.split doc does it explain this:
' a b '.split(None, 1) ['a', 'b '] ' a b '.split(None, 2) ['a', 'b']
.split method docs is more clear and describe this in a very simple way.
This is a better description of the current behavior:
"If sep is not specified or is None, a different splitting algorithm is applied. First, whitespace characters (spaces, tabs, newlines, returns, and formfeeds) are stripped from the start of the string. Then, words are separated by arbitrary length strings of whitespace characters. Consecutive whitespace delimiters are treated as a single delimiter ("' 1 \t 2 \n 3 '.split()" returns "['1', '2', '3']").
If maxsplit is nonzero, at most maxsplit number of splits occur, and the remainder of the string is returned as the final element of the list, unless it is empty. Splitting an empty string or a string consisting of just whitespace returns an empty list."