Issue 2809: string docstring doesn't mention that ' '.split() != ' '.split(' ') (original) (raw)

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:34 admin set github: 47058
2008-05-12 08🔞07 davidfraser set messages: +
2008-05-11 20:54:27 georg.brandl set messages: +
2008-05-11 18:24:55 davidfraser set nosy: + davidfrasermessages: +
2008-05-11 09:11:47 georg.brandl set status: open -> closedresolution: fixedmessages: +
2008-05-10 15:48:53 Neil Muller set assignee: georg.brandlnosy: + georg.brandlcomponents: + Documentationversions: + Python 2.6
2008-05-10 15:48:13 Neil Muller create