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: ''.split() docstring clarification
Type: Stage:
Components: Documentation Versions: Python 2.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: fdrake Nosy List: fdrake, jdnier, rhettinger
Priority: normal Keywords:

Created on 2002-07-16 03:20 by jdnier, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Messages (2)
msg11599 - (view) Author: David Niergarth (jdnier) Date: 2002-07-16 03:20
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).
msg11600 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2002-08-05 06:31
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.

History
Date User Action Args
2022-04-10 16:05:30adminsetgithub: 36901
2002-07-16 03:20:34jdniercreate