Skip to content
Advertisement

How can I parse an object in a python c-extention?

I have in Python an object such as:

JavaScript

And I want to read it in c in the

JavaScript

How can I access the members inside a pyObject for custom python data structures?

How can I do the opposite thing, assign values to an object that will later be called inside python?

edit:

As suggested by kpie, using the function PyObject_GetAttrString according to the documentation this should be equivalent to obj.n.

JavaScript

But when I ran this I get the error:

JavaScript

edit 2

I am compiling the c code using GCC with:

JavaScript

and then in the python script I add

JavaScript

Advertisement

Answer

The function PyObject_GetAttrString(obj,"attr") can read the attributes of a python class similarly to obj.attr as commented by kpie.

The issue was PyObject obj; that was not a pointer.

Advertisement