如何对包含引用的结构建模&x27;通过ctypes在python中定义什么?
尝试将引用的结构包装为以下定义 富科 例如,如何建模 福比 当然python不会解释这一点,我可以使用c_void_p而不是指针(Foo),并按如下方式转换它的值如何对包含引用的结构建模&x27;通过ctypes在python中定义什么?,python,c,ctypes,Python,C,Ctypes,尝试将引用的结构包装为以下定义 富科 例如,如何建模 福比 当然python不会解释这一点,我可以使用c_void_p而不是指针(Foo),并按如下方式转换它的值 F = clib.get_foo() cast(F.foo, pointer(Foo)) #although i'm not sure if it would work 但是,有没有办法在python类中对该结构建模?来源: 。在中,我们可以定义单元格类,并在class语句之后设置\u字段属性 如果我们将其应用于当前的问题,代码看起
F = clib.get_foo()
cast(F.foo, pointer(Foo)) #although i'm not sure if it would work
但是,有没有办法在python类中对该结构建模?来源:
。在中,我们可以定义单元格
类,并在class语句之后设置\u字段
属性
如果我们将其应用于当前的问题,代码看起来会像:
from ctypes import Structure, POINTER
class Foo(Structure):
pass
Foo._fields_ = [
("foo_ptr", POINTER(Foo)),
]
F = clib.get_foo()
cast(F.foo, pointer(Foo)) #although i'm not sure if it would work
from ctypes import Structure, POINTER
class Foo(Structure):
pass
Foo._fields_ = [
("foo_ptr", POINTER(Foo)),
]