[Python-bugs-list] [ python-Bugs-589965 ] "".split() ignores maxsplit arg

noreply@sourceforge.net noreply@sourceforge.net
Sun, 04 Aug 2002 19:14:55 -0700


Bugs item #589965, was opened at 2002-08-02 07:27
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=589965&group_id=5470

Category: Python Library
Group: None
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Gregory Bond (gnbond)
Assigned to: Nobody/Anonymous (nobody)
>Summary: "".split() ignores maxsplit arg

Initial Comment:
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)


----------------------------------------------------------------------

>Comment By: Martin v. Löwis (loewis)
Date: 2002-08-05 04:14

Message:
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.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=589965&group_id=5470