Small inconsistency between string.split and "".split

Alex Martelli aleaxit at yahoo.com
Fri Sep 17 13:57:54 EDT 2004


Michael Hudson <mwh at python.net> wrote:
   ...
> > 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:

Right, something like that.  As long as we need backwards compatibility
(==all the way to 3.0) that needs to be handled with care, of course...

> 
> 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 don't think so, either -- unless you put macros in TWO places,
perhaps:

DEF_PYFUN(foo, (PyObject* ob, int index))
{
   ...
}

PyMethodDef methods[] = {
    REF_PYFUN(foo, "docstring"),
    {0}
};

This, I suspect, might be possible, with DEF_PYFUN stashing the sig
string someplace (e.g. in a __def_pyfun__foo global) and REF_PYFUN
pulling out a reference to it...

> > nothing strange, and all correct, it seems to me.
> 
> Cool.  I should use pyrex more, I suspect.

Me too, I suspect -- it's really a cool way to write extensions for
Python.


Alex



More information about the Python-list mailing list