带有指向ctypes中自己类型的指针的struct

时间:2009-02-12 21:47:05

标签: python ctypes

我正在尝试使用ctypes映射结构定义:

struct attrl {
               struct attrl *next;
               char         *name;
               char         *resource;
               char         *value;
           };

我不确定如何处理ctypes映射中struct的“next”字段。定义如:

class attrl(Structure):
    _fields_ = [
        ("next", attrl),
        ("name", c_char_p), 
        ("resource", c_char_p), 
        ("value", c_char_p)
    ]

结果:

NameError: name 'attrl' is not defined

1 个答案:

答案 0 :(得分:3)

您需要等同于前瞻声明as described here