Accessing a Python Class from a C program

Paul Weimer PWeimer at harlandfs.com
Thu Nov 29 23:05:36 CET 2001


I have a C application that runs Python scripts but have run into a
situation that I have not been able to figure out.
A script is run with:
    PyRun_String(massaged, Py_file_input, m_pDict, m_pDict);
Where 'massaged' is the script; by our convention the result of the script
(usually some sort of string manipulation 
or calculation) is assigned to a variable 'result' with is then retrieved
with:
    PyObject *pval = PyDict_GetItemString(m_pDict, "result");
Some error checking is done with PyErr_Occurred (); if everything was ok I
use PyArg_Parse() to get the value in result.
This works fine if 'result' is a type like ant int or string but if it's a
class (in this case I want to use FixedPoint - it does 
exactly what I need) I don't know how to get the results back accurately. I
don't know whether there's a function in the
 C api that will do this or if there is method in the class that gets
accessed when PyDict_GetItemString() is called.

Thanks
Paul




More information about the Python-list mailing list