Getting structure elements in Cython

Surprisingly, I can not find a single example of obtaining structure elements by name (both on the Internet and in cython examples).

So, I get a pointer to the structure from the C function and would like to access these elements one by one and repack them into the python / dict list.

may be:

structPointer['propertyName']

or

structPointer.propertyName  

I want to get the effect structName->propertyName.

+3
source share
1 answer

The second syntax is correct, but you must have an extern expression for the structure type:

cdef extern from "someheader.h":
   struct properties_t:
      int value1
      int value2
   properties_t* getthem()

cdef void foo():
   cdef properties_t* prop
   prop = getthem()
   i = prop.value1
+5
source

Source: https://habr.com/ru/post/1787412/


All Articles