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.

classification
Title: str.split bug when using sep = None and maxsplit
Type: behavior Stage:
Components: Versions: Python 2.4, Python 2.5
process
Status: closed Resolution: duplicate
Dependencies: Superseder: split(None, maxsplit) does not strip whitespace correctly
View: 1123
Assigned To: Nosy List: QuantumTim, brett.cannon, gvanrossum
Priority: normal Keywords:

Created on 2007-10-05 13:20 by QuantumTim, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg56237 - (view) Author: Tim Gordon (QuantumTim) Date: 2007-10-05 13:20
From the docs for str.split:
"If sep is not specified or is None... First, whitespace characters are 
stripped from both ends. Then, words are separated by arbitrary length 
strings of whitespace characters."

However, ' a b c '.split(None, 1) returns ['a', 'b c '] indicating that 
the "stripped from both ends" isn't taking place, but that it's 
removing whitespace as it goes and never gets to the end as it stops 
parsing when it hits the first split.

Note this is easily worked around by calling str.strip().split(None, 
1), but it would be good not to have to.

I've tested this on windows version 2.5, and 2.4.4 for Debian
msg56242 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2007-10-05 17:21
I know there is another filed bug on this topic, I just need to find it.
msg56254 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2007-10-06 22:35
It was deemed a documentation bug.
msg56258 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2007-10-07 20:05
issue1123 was the issue I was thinking of.  Setting that as a superceder
as 1123 was closed prematurely.
History
Date User Action Args
2022-04-11 14:56:27adminsetgithub: 45581
2007-10-07 20:06:03brett.cannonsetstatus: open -> closed
resolution: duplicate
2007-10-07 20:05:53brett.cannonsetsuperseder: split(None, maxsplit) does not strip whitespace correctly
messages: + msg56258
2007-10-06 22:35:24gvanrossumsetnosy: + gvanrossum
messages: + msg56254
2007-10-05 17:21:58brett.cannonsetnosy: + brett.cannon
messages: + msg56242
2007-10-05 13:22:01QuantumTimsettitle: str.split bug -> str.split bug when using sep = None and maxsplit
2007-10-05 13:21:11QuantumTimsettitle: str.split possible bug -> str.split bug
2007-10-05 13:20:23QuantumTimcreate