0

Python 3.6 I import mylib.so, a C shared library. In this lib is a structure, mystruct, with three elements, {int a, float b, and uint8_t c}. I can import this structure into Python3. The structure is filled by calls to functions in the library. type of struct_p is

Question: How do I access the contents of the structure in Python?

from ctypes import *
mylib = CDLL('/home/tomdean/mylib.so')
from mylib import ( mylib,p_mystruct ) 
struct_p = p_mystruct(None)
rc = mylib.fills(struct_p)
print(type(struct_p))

1 Answers1

0

I thought this should have already been answered. It has.

http://www.ifnamemain.com/posts/2013/Dec/10/c_structs_python/

I just need to define a structure in python that mimics the C structure.

OOPS, this is not an answer to my problem. This works, passing a structure from python to C.

I want to define a structure in python and get its contents from a lib.so.

The answer is really here. How to dereference a memory location from python ctypes?