I have been trying to get to grips with extending python with C, and so far, based on the documentation, I have had reasonable success in writing small C functions and extending it with Python.
However, I am now struck on a rather simple problem - to which I am not able to find a solution. So, what I'd like to do is pass a double list
to my C function. For example, to pass an int
, I do the following:
int squared(int n)
{
if (n > 0)
return n*n;
else
return 0;
}
static PyObject*
squaredfunc(PyObject* self, PyObject* args)
{
int n;
if (!PyArg_ParseTuple(args, "i", &n))
return NULL;
return Py_BuildValue("i", squared(n));
}
This passes the int
n
with no problems to my C function named squared
.
But, how does one pass a list
to the C function? I did try to google it and read the docs, and so far, I havent found anything useful on this.
Would really appreciate if someone could point me in the right direction.
Thanks.
"O"
rather than"i"
to say that your accepting an arbitrary object. – Nisanint n
declaration to reflect this? Should I just be doingdouble n[]
? – AmyPyObject *lst;
, or something similar I would think. – Nisan