内部类无法使用Python Ctypes看到另一个内部类的定义

问题描述 投票:0回答:1

我尝试使用 Ctypes 将 C 代码片段转换为 Python,但它不起作用。 C代码如下:

struct A
{
    struct B
    {
        // Empty
    };

    struct C
    {
        B b;
    };
};

我的Python代码是:

from ctypes import Structure

class A(Structure):
    class B(Structure):
        _field_ = []

    class C(Structure):
        _field = [("b", A.B)]   # Error: Unresolved reference 'A'

你能提示我我做错了什么吗?谢谢!

python ctypes
1个回答
0
投票

我相信您的代码中有一个拼写错误,特别是

_field_
部分。 问题是它应该是
_fields_
而不是
_field_

` from ctypes import Structure

A级(结构): B级(结构): 字段 = []

class C(Structure):
    _fields_ = [("b", A.B)]

`

希望这有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.