Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何对包含引用的结构建模&x27;通过ctypes在python中定义什么?_Python_C_Ctypes - Fatal编程技术网

如何对包含引用的结构建模&x27;通过ctypes在python中定义什么?

如何对包含引用的结构建模&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字段属性 如果我们将其应用于当前的问题,代码看起

尝试将引用的结构包装为以下定义

富科

例如,如何建模

福比

当然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字段
属性

如果我们将其应用于当前的问题,代码看起来会像:

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)),
]