Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Keywordargument in string.split

10 views
Skip to first unread message

P.J.W.S. Vrijlandt

unread,
Jan 26, 2000, 3:00:00 AM1/26/00
to pytho...@python.org
Hi all,

I have this error I don't quite understand.
Why can't I give 'sep' as a keyword argument?

It seems that the string module I import, is not the string.py in the
standard distribution but a not-quite-equivalent c-implementation of
it.

Patrick

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


Python 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on
win32 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import string
>>> string.split('abcd', sep = 'c')
Traceback (innermost last):
File "<pyshell#1>", line 1, in ?
string.split('abcd', sep = 'c')
TypeError: this function takes no keyword arguments
>>> def split(s, sep=None, maxsplit=0): # = string.split
print s, sep,
maxsplit >>> split('abcd', sep = 'c')
abcd c 0


Oleg Broytmann

unread,
Jan 26, 2000, 3:00:00 AM1/26/00
to P.J.W.S. Vrijlandt
On Wed, 26 Jan 2000, P.J.W.S. Vrijlandt wrote:
> It seems that the string module I import, is not the string.py in the
> standard distribution but a not-quite-equivalent c-implementation of
> it.

But of course! Read the very string.py and find strop there...

Oleg.
----
Oleg Broytmann Foundation for Effective Policies p...@phd.russ.ru
Programmers don't die, they just GOSUB without RETURN.

P.J.W.S. Vrijlandt

unread,
Jan 27, 2000, 3:00:00 AM1/27/00
to pytho...@python.org
I wrote:

> I have this error I don't quite understand.
> Why can't I give 'sep' as a keyword argument?
>

> It seems that the string module I import, is not the string.py in the
> standard distribution but a not-quite-equivalent c-implementation of
> it.

I got replies pointing to 'strop', which is a c-implementation of
string, and is imported by string.py

But what is the header (def) of split in strop?
(and why is it different)

>
> Python 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on
> win32 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >>> import string
> >>> string.split('abcd', sep = 'c')
> Traceback (innermost last):
> File "<pyshell#1>", line 1, in ?
> string.split('abcd', sep = 'c')
> TypeError: this function takes no keyword arguments
> >>> def split(s, sep=None, maxsplit=0): # = string.split
> print s, sep,
> maxsplit >>> split('abcd', sep = 'c')
> abcd c 0
>

> --
> http://www.python.org/mailman/listinfo/python-list
>
Met vriendelijke groet,

Patrick Vrijlandt


Michael Hudson

unread,
Jan 27, 2000, 3:00:00 AM1/27/00
to
"P.J.W.S. Vrijlandt" <P.J.W.S....@INT.azg.nl> writes:

> I wrote:
>
> > I have this error I don't quite understand.
> > Why can't I give 'sep' as a keyword argument?
> >
> > It seems that the string module I import, is not the string.py in the
> > standard distribution but a not-quite-equivalent c-implementation of
> > it.
>
> I got replies pointing to 'strop', which is a c-implementation of
> string, and is imported by string.py
>
> But what is the header (def) of split in strop?
> (and why is it different)

Supporting keyword arguments for C extensions requires a little bit of
work on the part of the extension writer. Not much, but a bit.

This work doesn't seem to have been done for many modules in the
standard distribution. This could be for two reasons:

1) The support for C extensions taking keyword parameters is quite
new, and not much has caught up yet (no idea whether this is true)

2) The standard C extensions are so commonly used that people don't
need to use kwargs (I'd never noticed the lack before).

3) PyArg_ParseTupleAndKeywords is significantly slower than
PyArg_ParseTuple, even in the no kwarg case (I don't believe this
is the case, but it's possible).

It seems that sha and parser accept keyword arguments, and nothing
else. Would patches to remedy this be accepted? Looks easy enough to
acheive, if a little tedious.

Cheers,
Michael

0 new messages