classification
Title: Allow "maxsplit" argument to str.split() to be passed as a keyword argument
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ezio.melotti Nosy List: eric.araujo, ezio.melotti, ncoghlan, python-dev, tshepang
Priority: normal Keywords: patch

Created on 2012-02-22 01:54 by ncoghlan, last changed 2012-02-26 07:44 by ezio.melotti. This issue is now closed.

Files
File name Uploaded Description Edit
issue14081.diff ezio.melotti, 2012-02-22 03:16 Patch + tests review
issue14081-2.diff ezio.melotti, 2012-02-24 10:30
Messages (7)
msg153920 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2012-02-22 01:54
Currently, setting maxsplit for the default "any whitespace" behaviour requires the following cryptic incantation:

    'do re mi fa'.split(None, 1)

That would be significantly more comprehensible as:

    'do re mi fa'.split(maxsplit=1)

(I noticed this when trying to figure out why http://hyperpolyglot.org/scripting#split-notes resorted to using the re module to achieve this)
msg153924 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2012-02-22 03:16
+1
Patch attached.
msg154130 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2012-02-24 10:30
New patch that changes .rsplit() too and updates docs and docstrings.
msg154194 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2012-02-25 07:16
LGTM.

(Nick: I think the author directly translated the regex function calls from other languages to using re in Python.)
msg154222 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2012-02-25 09:41
Ezio: I spotted an extraneous '[' hanging around in the updated doc signature for split, but otherwise looked fine.

Éric: you're probably right, but I was sending them a note to suggest a simpler alternative, only to discover that the obvious approach of "maxsplit=1" didn't actually work.
msg154311 - (view) Author: Roundup Robot (python-dev) Date: 2012-02-26 07:40
New changeset db968ac2b82c by Ezio Melotti in branch 'default':
#14081: The sep and maxsplit parameter to str.split, bytes.split, and bytearray.split may now be passed as keyword arguments.
http://hg.python.org/cpython/rev/db968ac2b82c
msg154312 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2012-02-26 07:44
Fixed!
Thanks for the reviews and for spotting the extra '['.
(While suggesting the use of maxsplit, be aware that str.split uses -1 as default value, whereas re.split uses 0.)
History
Date User Action Args
2012-02-26 07:44:14ezio.melottisetstatus: open -> closed
resolution: fixed
messages: + msg154312

stage: commit review -> resolved
2012-02-26 07:40:08python-devsetnosy: + python-dev
messages: + msg154311
2012-02-25 09:41:45ncoghlansetmessages: + msg154222
2012-02-25 07:16:24eric.araujosetnosy: + eric.araujo
messages: + msg154194
2012-02-24 16:05:25tshepangsetnosy: + tshepang
2012-02-24 10:31:00ezio.melottisetfiles: + issue14081-2.diff

messages: + msg154130
2012-02-22 03:16:52ezio.melottisetfiles: + issue14081.diff

assignee: ezio.melotti

keywords: + patch
nosy: + ezio.melotti
messages: + msg153924
stage: needs patch -> commit review
2012-02-22 01:54:09ncoghlancreate