PyArg_ParseTuple() and oprtional remaining argument lists

Michael P. Reilly arcege at shore.net
Wed Dec 1 08:25:14 EST 1999


Adrian Eyre <a.eyre at optichrome.com> wrote:
:> I also have trouble using PyArg_ParseTuple(...) with a single item,
:> e.g.
:> 	if (PyArg_Parse(args,"i",&index) && (index >= 0)) {
:> is ok, but
:> 	if (PyArg_ParseTuple(args,"i",&index) && (index >= 0)) {

: Aha. That's the clue. Make sure that your PyMethodDef struct is like
: this:

: static struct PyMethodDef methods[] = {
:     { "method1",   method1, 1 },
:     { "method2",   method2, 1 },
:     { NULL,        NULL,    0 } 
: };

It might be better to use METH_VARARGS instead of 1, in case the value
changes in a future release.

  -Arcege





More information about the Python-list mailing list