This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author nirs
Recipients nirs
Date 2007-09-07.01:18:40
SpamBayes Score 7.442122e-05
Marked as misclassified No
Message-id <1189127921.0.0.701786903755.issue1123@psf.upfronthosting.co.za>
In-reply-to
Content
string object .split doc say (http://docs.python.org/lib/string-
methods.html):

    "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 both ends."

If the maxsplit argument is set and is smaller then the number of 
possible parts, whitespace is not removed.

Examples:

>>> 'k: v\n'.split(None, 1)
['k:', 'v\n']

Expected: ['k:', 'v']

>>> u'k: v\n'.split(None, 1)
[u'k:', u'v\n']

Expected: [u'k:', u'v']

With larger values of maxsplits, it works correctly:

>>> 'k: v\n'.split(None, 2)
['k:', 'v']
>>> u'k: v\n'.split(None, 2)
[u'k:', u'v']

This looks like implementation bug, because there it does not make sense 
that the striping depends on the maxsplit argument, and it will be hard 
to explain such behavior.

Maybe the striping should be removed in Python 3? It does not make sense 
to strip a string behind your back when you want to split it, and the 
caller can easily strip the string if needed.
History
Date User Action Args
2007-09-07 01:18:41nirssetspambayes_score: 7.44212e-05 -> 7.442122e-05
recipients: + nirs
2007-09-07 01:18:41nirssetspambayes_score: 7.44212e-05 -> 7.44212e-05
messageid: <1189127921.0.0.701786903755.issue1123@psf.upfronthosting.co.za>
2007-09-07 01:18:40nirslinkissue1123 messages
2007-09-07 01:18:40nirscreate