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: string docstring doesn't mention that ' '.split() != ' '.split(' ')
Type: Stage:
Components: Documentation Versions: Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: Neil Muller, davidfraser, georg.brandl
Priority: normal Keywords: patch

Created on 2008-05-10 15:48 by Neil Muller, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
split_docstring.diff Neil Muller, 2008-05-10 15:48 Update docstring for split in stringobject and unicodeobject to note behaviour of split() vs split(' ')
Messages (5)
msg66536 - (view) Author: Neil Muller (Neil Muller) Date: 2008-05-10 15:48
split with no sep specified will not return an empty string, whereas
split with sep specified will. 

The attached patch updates the docstring to reflect this for str.split
and unicode.split.
msg66616 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-05-11 09:11
Committed a different (shorter) docstring change to the same effect as
r63050.
msg66647 - (view) Author: David Fraser (davidfraser) Date: 2008-05-11 18:24
I don't think this really addresses the issue properly...

The original docstring read:
+Note that not specifying sep (or using None) will cause\n\
+empty strings to be removed from the output. thus ' '.strip()\n\
+returns []. while ' '.strip(' ') returns ['', ''].
(Obviously strip is wrong here, it should be split)

The committed docstring reads:
+If sep is not specified or is None, any whitespace string is a
separator and leading and trailing whitespace is stripped before splitting.

But the point is not just that leading and trailing whitespace is
stripped; ''.strip() returns [] while ''.strip(' ') returns ['']. This
is probably the most unexpected corner case; it seems to be better to
say that empty strings are removed from the output.
msg66668 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-05-11 20:54
Okay, r63092 should satisfy you then. :)
msg66714 - (view) Author: David Fraser (davidfraser) Date: 2008-05-12 08:18
Yes that's fantastic, thanks :-)
History
Date User Action Args
2022-04-11 14:56:34adminsetgithub: 47058
2008-05-12 08:18:07davidfrasersetmessages: + msg66714
2008-05-11 20:54:27georg.brandlsetmessages: + msg66668
2008-05-11 18:24:55davidfrasersetnosy: + davidfraser
messages: + msg66647
2008-05-11 09:11:47georg.brandlsetstatus: open -> closed
resolution: fixed
messages: + msg66616
2008-05-10 15:48:53Neil Mullersetassignee: georg.brandl
nosy: + georg.brandl
components: + Documentation
versions: + Python 2.6
2008-05-10 15:48:13Neil Mullercreate