unpacking Python tuple in C

Mike Müller mmueller at dgfz.de
Wed Dec 13 04:13:04 EST 2000


Hi,

Calling Python from C I get a PythonTupleObject

PyObject *result = PyObject_CallMethod(...)

PyTuple_Check(result)  is 1 so its really a tuple!

The tuple contains only Python floats.

Using

PyArg_ParseTuple(result, "dd",  &double1, &double2)

does not change double1, or double2.

 I can get  an item of the tuple:

PyObject* floatFromPy0 = PyTuple_GetItem(result, 0);
  *double1= PyFloat_AsDouble(floatFromPy0)

since the tuple is pretty long and I need all of the tuple items
PyTuple_GetItem seems to not the best solution.

Any hints how I can get all the tuple items into C doubles?

Thanks.

Mike





More information about the Python-list mailing list