[Python-bugs-list] [ python-Bugs-582071 ] ''.split() docstring clarification
noreply@sourceforge.net
noreply@sourceforge.net
Sun, 04 Aug 2002 23:31:08 -0700
Bugs item #582071, was opened at 2002-07-15 22:20
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=582071&group_id=5470
Category: Documentation
Group: Python 2.3
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: David Niergarth (jdnier)
Assigned to: Fred L. Drake, Jr. (fdrake)
Summary: ''.split() docstring clarification
Initial Comment:
I'm suggesting a small clarification in the docstring for the
split method of strings.
>>> print ''.split.__doc__
S.split([sep [,maxsplit]]) -> list of strings
Return a list of the words in the string S, using sep as the
delimiter string. If maxsplit is given, at most maxsplit
splits are done. If sep is not specified, any whitespace
string is a separator.
>>>
I think that last sentence would better read:
If sep is not specified or is None, any whitespace
string is a separator.
adding "or is None".
For the longest time I thought is wasn't possible to specify
maxsplit and still split on "any whitespace." It turns out
None is the magic value you can use to indicate "any
whitespace." For example,
>>> 'a\tb c d'.split(None, 2)
['a', 'b', 'c d']
This is suggested by the signature of the old string.split
function
def split(s, sep=None, maxsplit=-1):
although the new-ish ''.split() method does not accept
keyword args.
This little clarification would have helped in my case
anyway (re.split() notwithstanding).
----------------------------------------------------------------------
>Comment By: Raymond Hettinger (rhettinger)
Date: 2002-08-05 01:31
Message:
Logged In: YES
user_id=80475
Thank you for the contribution.
Added "or is None" to the docstring.
Committed as stringobject.c. 2.174 and backported to
2.147.6.7
Closing bug.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=582071&group_id=5470