extending Python - passing nested lists
Christian Meesters
meesters at uni-mainz.de
Mon Jan 28 10:10:10 EST 2008
Hi,
I would like to write a C-extension function for an application of mine. For
this I need to pass a nested list (like: [[a, b, c], [d, e, f], ...], where
all letters are floats) to the C-function. Now, with the code I have the
compiler is complaining: "subscripted value is neither array nor pointer".
Can somebody tell me what's wrong?
Here a code snippet to reproduce this problem:
static PyObject *_foo(PyObject *self, PyObject *args) {
int i;
long lenght;
float ax, ay, az;
PyObject *dummy_list;
if (!PyArg_ParseTuple(args, "O", &dummy_list))
return NULL;
dummy_list = PySequence_Fast(dummy_list, "argument must be iterable");
lenght = PyObject_Length(dummy_list);
for (i=0; i < lenght; i++) {
// part which does not work:
ax = dummy_list[i][0];
ay = dummy_list[i][1];
az = dummy_list[i][2];
}
return 0;
}
TIA
Christian
More information about the Python-list
mailing list