Accessing a Python Class from a C program

Martin von Loewis loewis at informatik.hu-berlin.de
Fri Nov 30 07:44:21 EST 2001


Paul Weimer <PWeimer at harlandfs.com> writes:

>     PyObject *pval = PyDict_GetItemString(m_pDict, "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.

It works the very same way: pval will be a class the class instance
object that result was assigned to.

I don't know what you want to do with that result, just tell us how
you would process the result in Python, and we tell you how to write
that in C. E.g. if you were doing

   print result.counter

then in C, this would read

   PyObject *counter = PyObject_GetAttrString(pval, "counter");

HTH,
Martin




More information about the Python-list mailing list