classification
Title: str.split() takes no keyword arguments (Should this be expected?)
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 2.5
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, georg.brandl, sergioc
Priority: low Keywords:

Created on 2007-09-18 16:59 by sergioc, last changed 2007-09-20 16:59 by sergioc. This issue is now closed.

Messages (5)
msg56002 - (view) Author: Sergio Correia (sergioc) Date: 2007-09-18 16:59
str.split() does not accept maxsplits as a keyword argument.

If i want to split a string, and, say, get its first word, I do this:

>>> 'SPAM eggs eggs spam spam ham'.split(None, 1)[0]
'SPAM'

However, as documented on help(str.split), the separator is optional, so
 I expected this to work:

>>> 'SPAM eggs eggs spam spam ham'.split(maxsplit=1)

Traceback (most recent call last):
  File "<pyshell#8>", line 1, in <module>
    'SPAM eggs eggs spam spam ham'.split(maxsplit=1)
TypeError: split() takes no keyword arguments

I feel allowing keyword arguments is convenient, but is there a reason
behind not allowing them?
msg56003 - (view) Author: Sergio Correia (sergioc) Date: 2007-09-18 17:01
As a side note, this is slightly related with:
http://mail.python.org/pipermail/python-dev/2000-October/009694.html
http://bugs.python.org/issue1123
(but check the date of the first link!)
msg56023 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2007-09-19 02:28
This is expected as str.split() is implemented in C and C code only has
keyword arguments if someone puts in the time and effort to support
them.  Support could be added if so desired.  But it does slow down
argument passing.  If you look you will notice that none of str's
methods have keyword support.

Changing this to an rfe.
msg56058 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-09-20 16:46
Added to the documentation that string methods don't take keyword args
in rev. 58219. Closing this as "works for me".
msg56059 - (view) Author: Sergio Correia (sergioc) Date: 2007-09-20 16:59
Thanks for the update,
Sergio
History
Date User Action Args
2007-09-20 16:59:08sergiocsetmessages: + msg56059
2007-09-20 16:46:17georg.brandlsetstatus: open -> closed
resolution: works for me
messages: + msg56058
nosy: + georg.brandl
2007-09-19 02:28:12brett.cannonsetpriority: normal -> low
type: behavior -> enhancement
messages: + msg56023
nosy: + brett.cannon
2007-09-18 21:18:01jafosetpriority: normal
2007-09-18 17:01:46sergiocsetmessages: + msg56003
2007-09-18 16:59:52sergioccreate