![]() | Python functions can be called from C |
![]() | Step 1: for each argument, convert C data to Python objects and collect these in a tuple
PyObject *arglist; double x, y; /* double x,y -> tuple with two Python float objects: */ arglist = Py_BuildValue("(dd)", x, y); |
![]() | Step 2: call the Python function
PyObject *result; /* return value from Python function */ PyObject *func1; /* Python function object */ result = PyEval_CallObject(func1, arglist); |
![]() | Step 3: convert result to C data
double r; /* result is a Python float object */ r = PyFloat_AS_DOUBLE(result); |