Python3.6I导入mylib.so,这是一个C共享库。在这个库中有一个结构mystruct,它有三个元素:{int,uint8_t b和uint8_t c}。我可以将这个结构导入到Python3中。该结构由对库中函数的调用填充。struct_p的类型为
问:如何在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))发布于 2019-09-16 02:04:11
我想这个问题应该已经被回答了。确实是这样。
http://www.ifnamemain.com/posts/2013/Dec/10/c_structs_python/
我只需要在python中定义一个模仿C结构的结构。
哦,这不是我的问题的答案。这是可行的,将一个结构从python传递到C。
我想在python中定义一个结构,并从lib.so中获取它的内容。
答案就在这里。How to dereference a memory location from python ctypes?
https://stackoverflow.com/questions/57946583
复制相似问题