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() ignores maxsplit arg
Type: Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: gnbond, loewis
Priority: normal Keywords:

Created on 2002-08-02 05:27 by gnbond, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Messages (2)
msg11806 - (view) Author: Gregory Bond (gnbond) Date: 2002-08-02 05:27
lightning$ python
Python 2.1.1 (#4, Oct 10 2001, 11:07:04) 
[GCC 2.95.3 20010315 (release)] on sunos5
Type "copyright", "credits" or "license" for more
information.
>>> s = 'a b c d e f g'
>>> s.split()
['a', 'b', 'c', 'd', 'e', 'f', 'g']
>>> s.split(maxsplit=3)
['a', 'b', 'c', 'd', 'e', 'f', 'g']
>>> import string
>>> string.split(s, maxsplit=3)
['a', 'b', 'c', 'd e f g']
>>> 
lightning$ 

i.e. s.split(maxsplit=3) is NOT the same as
string.split(s, maxsplit=3)
msg11807 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2002-08-05 02:14
Logged In: YES 
user_id=21627

This has been fixed in Python 2.2, which reports

>>> s.split(maxsplit=3)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: split() takes no keyword arguments

That means that the keyword argument is not supported; you
must write this as

s.split(' ', 3)

If you do not want to give a string separator, you need to
pass None.
History
Date User Action Args
2022-04-10 16:05:32adminsetgithub: 36965
2002-08-02 05:27:27gnbondcreate