I'm trying to get a list as an argument in a C extension in Python, the function and the wrapper (Function's table is omitted):
#include <Python.h>
int MyFunction(int a_triplet[]){
printf("%i\n", a_triplet[0]);
return 0;
}
static PyObject* any_function(PyObject* self, PyObject* args)
{
PyObject *lst;
if (!PyArg_ParseTuple(args, "O", &lst))
return NULL;
return Py_BuildValue("[i]", MyFunction(lst)); // Returns error
}
I'm a bit lost in the last line:
return Py_BuildValue("[i]", MyFunction(lst));
And in the Python function I have this:
print (Module.any_function([67, 93, 56]))
How can I get the list passed in Python to the C extension? I'm a lost because if I write a function and a wrapper to receive an integer, works perfectly:
#include <Python.h>
int MyFunction(int n){
printf("%i", n);
return 0;
}
static PyObject* alice_bob(PyObject* self, PyObject* args)
{
int n;
if (!PyArg_ParseTuple(args, "i", &n))
return NULL;
return Py_BuildValue("i", MyFunction(n));
}