Skip to content

Allow "maxsplit" argument to str.split() to be passed as a keyword argument #58289

Closed

Description

@ncoghlan
BPO 14081
Nosy @ncoghlan, @ezio-melotti, @merwok
Files
  • issue14081.diff: Patch + tests
  • issue14081-2.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/ezio-melotti'
    closed_at = <Date 2012-02-26.07:44:14.924>
    created_at = <Date 2012-02-22.01:54:09.836>
    labels = ['interpreter-core', 'type-feature']
    title = 'Allow "maxsplit" argument to str.split() to be passed as a keyword argument'
    updated_at = <Date 2012-02-26.07:44:14.922>
    user = 'https://github.com/ncoghlan'

    bugs.python.org fields:

    activity = <Date 2012-02-26.07:44:14.922>
    actor = 'ezio.melotti'
    assignee = 'ezio.melotti'
    closed = True
    closed_date = <Date 2012-02-26.07:44:14.924>
    closer = 'ezio.melotti'
    components = ['Interpreter Core']
    creation = <Date 2012-02-22.01:54:09.836>
    creator = 'ncoghlan'
    dependencies = []
    files = ['24597', '24625']
    hgrepos = []
    issue_num = 14081
    keywords = ['patch']
    message_count = 7.0
    messages = ['153920', '153924', '154130', '154194', '154222', '154311', '154312']
    nosy_count = 5.0
    nosy_names = ['ncoghlan', 'ezio.melotti', 'eric.araujo', 'tshepang', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue14081'
    versions = ['Python 3.3']

    Activity

    1. ncoghlan commented on Feb 22, 2012

      @ncoghlan
      ContributorAuthor

      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)

    2. ezio-melotti commented on Feb 22, 2012

      @ezio-melotti
      Member

      +1
      Patch attached.

    3. self-assigned this
      on Feb 22, 2012
    4. ezio-melotti commented on Feb 24, 2012

      @ezio-melotti
      Member

      New patch that changes .rsplit() too and updates docs and docstrings.

    5. merwok commented on Feb 25, 2012

      @merwok
      Member

      LGTM.

      (Nick: I think the author directly translated the regex function calls from other languages to using re in Python.)

    6. ncoghlan commented on Feb 25, 2012

      @ncoghlan
      ContributorAuthor

      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.

    7. python-dev commented on Feb 26, 2012

      python-devmannequin
      Mannequin

      New changeset db968ac2b82c by Ezio Melotti in branch 'default':
      bpo-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

    8. ezio-melotti commented on Feb 26, 2012

      @ezio-melotti
      Member

      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.)

    9. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions