Bugs item #1106694, was opened at 2005-01-21 14:30 Message generated for change (Comment added) made by calvin 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 ---------------------------------------------------------------------- Comment By: Wummel (calvin) Date: 2005-01-24 13:34 Message: Logged In: YES user_id=9205 Specifying None as separator gives you (as documented) the split-on-mulitple-whitespace behaviour. This applies to both string.split() and the split() string method. So skipping the separator arg is not needed. However, I agree to your wish that the string method split() should accept the "maxsplit" as a keyword argument. It is more backward compatible to the old string.split() function that way. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1106694&group_id=5470 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com