Small inconsistency between string.split and "".split
Michael Hudson
mwh at python.net
Fri Sep 17 09:36:20 EDT 2004
aleaxit at yahoo.com (Alex Martelli) writes:
> Michael Hudson <mwh at python.net> wrote:
>
> > aleaxit at yahoo.com (Alex Martelli) writes:
> >
> > > Having ALL C-coded functions and methods that accept any argument
> > > accept keyword-style arguments in particular would surely lead to a
> > > more consistent language,
> >
> > [...]
> >
> > This whole area isn't particularly pretty. In general it would be
>
> Indeed, it isn't.
>
> > better to expose more of an extension functions signature *outside*
> > the function, for efficiency, introspection and even things like
>
> ...and consistency with the way Python-coded functions work.
Heh, yes, that too :-)
> > psyco. METH_O, METH_NOARGS are a step in this direction -- but you
> > can't pass a keyword argument to a METH_O function (not that one would
> > want to, very often, but it's still a potential inconsistency).
>
> Right; it could be remedied by letting a macro otherwise equivalent to
> METH_O know about that one argument's name.
But... how? I guess the PyMethodDef struct could grow an ml_signature
field... wouldn't it be nice if you could do:
static PyObject*
foo(PyObject* ob, int index)
{
...;
}
PyMethodDef methods[] = {
{"foo", foo, "O[ob]i[index]", "docstring"},
{NULL, NULL}
}
? Even nicer if you didn't have to write the signature by hand.
Unfortunately, I don't think you can do this in standard C.
> > I wonder what Pyrex does...
>
> for:
> def example(aa, bb):
> pass
>
> it generates (name mangling apart, I'm demangling for legibility):
>
> static PyObject* example(PyObject *self, PyObject *args, PyObject *kwds)
> {
> PyObject *aa = 0;
> PyObject *bb = 0;
> static char *argnames[] = {"aa", "bb", 0};
>
> if(!PyArg_ParseTupleAndKeywords(args,kwds,"OO",argnames,&aa,&bb))
> return 0;
>
> etc, etc, and METH_VARARGS|METH_KEYWORDS in the PyMethodDef array. IOW,
> nothing strange, and all correct, it seems to me.
Cool. I should use pyrex more, I suspect.
Cheers,
mwh
--
As it seems to me, in Perl you have to be an expert to correctly make
a nested data structure like, say, a list of hashes of instances. In
Python, you have to be an idiot not to be able to do it, because you
just write it down. -- Peter Norvig, comp.lang.functional
More information about the Python-list
mailing list