[ python-Bugs-1106694 ] split() takes no keyword arguments

SourceForge.net noreply at sourceforge.net
Fri Jan 21 14:30:04 CET 2005


Bugs item #1106694, was opened at 2005-01-21 13:30
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1106694&group_id=5470

Category: Python Interpreter Core
Group: Not a Bug
Status: Open
Resolution: None
Priority: 5
Submitted By: Vinz (boukthor)
Assigned to: Nobody/Anonymous (nobody)
Summary: split() takes no keyword arguments

Initial Comment:
I'm running python 2.4 on a Linux box (Mandrake cooker
10.2).

Since the string functions have been implemented as
method of string instances, there's little use for the
string module (except for constants). However, the
behaviour of the 'split' method is slightly different
from the one in the string module : it does not accept
keyword arguments.

This is annoying because the default separator argument
('any whitespace') cannot be provided manually (at
least I couldn't find a way to do it) and that means
that you can not use the default separator while
specifying a maxsplit argument (if you specify
maxsplit, you need to give a separator manually because
it comes first in the arg list), unless you use
"string.split" (and "import string") syntax.

Examples :
>>> "foo bar\tbaz\nqux".split()
['foo', 'bar', 'baz', 'qux']
>>> string.split("foo bar\tbaz\nqux")
['foo', 'bar', 'baz', 'qux']
>>> "foo bar\tbaz\nqux".split(" \t\n") # this is ok,
just illustrating that you cannot emulate the default
behaviour if you provide a separator manually
['foo bar\tbaz\nqux']
>>> string.split("foo bar\tbaz\nqux", maxsplit=2) #
what I want to do
['foo', 'bar', 'baz\nqux']
>>> "foo bar\tbaz\nqux".split(maxsplit=2) # what I get
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: split() takes no keyword arguments
>>> "foo bar\tbaz\nqux".split(2) # cannot skip the sep arg
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: expected a character buffer object


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

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


More information about the Python-bugs-list mailing list