PyArg_ParseTupleAndKeywords in Python3.1
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Mon Dec 21 02:35:36 EST 2009
En Sat, 19 Dec 2009 07:36:59 -0300, Emeka <emekamicro at gmail.com> escribió:
> Okay if that is the case, why do we need it? By having int a = 65, b =
> 66 ,
> why should we also have *kwlist[]?
>
>
>
> static PyObject* foo(PyObject *self, PyObject *args, PyObject *kwrds)
> {
> int a=65, b=66;
> char *kwlist[] = {"a", "b", NULL};
> if (!PyArg_ParseTupleAndKeywords(args, kwrds, "|CC", kwlist, &a,
> &b))
> return NULL;
> return Py_BuildValue("(CC)", a, b);
> }
It's not related to default values. foo(x=30) should raise an error; the
allowed parameter names are only 'a' and 'b', not 'x'.
--
Gabriel Genellina
More information about the Python-list
mailing list