If I am extending Python in C, I can parse arguments provided on the Python side using functions like PyArg_ParseTuple()
. However, this only allows me to specify scalar arguments, or tuple arguments of known length. How do I deal with the case where the user calls my function from Python with a tuple of arbitrary length? For example:
import foo
foo.bar([1, 2, 3])
foo.bar([4, 5])
Here, bar()
is defined in C, and its arguments are parsed using PyArg_ParseTuple()
, which copies the argument values to a local variable. I have to specify the argument format and an address into which to copy the parsed value. For instance:
int i,j;
PyArg_ParseTuple(args, "i", &i)
/* or */
PyArg_ParseTuple(args, "(ii)", &i, &j);
But what I want is something like this:
int *i;
int ni;
PyArg_ParseTuple(args, "(i...)", &ni, i);
where i is an array, and ni is the number of elements in the array. Is this possible?