我正在围绕^{struct ifaddrs
类型,其第一个字段是指向另一个struct ifaddrs
的指针。在
struct ifaddrs {
struct ifaddrs *ifa_next; /* Pointer to the next structure. */
... /* SNIP!!11 */
};
但是,在Python中表示:
^{pr2}$给出此错误:
matt@stanley:~/src/pydlnadms$ ./getifaddrs.py
Traceback (most recent call last):
File "./getifaddrs.py", line 58, in <module>
class struct_ifaddrs(Structure):
File "./getifaddrs.py", line 61, in struct_ifaddrs
('ifa_next', POINTER(struct_ifaddrs)),
NameError: name 'struct_ifaddrs' is not defined
在完成类定义之前,struct_ifaddrs
不会绑定到当前作用域。当然,作为指针类型,很明显,struct_ifaddrs
的定义在声明过程中并不需要,就像在C中一样,但是在以后的使用中需要取消对该类型的定义。我该怎么办?在
这个怎么样?在
正如paulmcguire在评论中所指出的,这被记录为the ctypes documentation和yet another time in the same docs中这个问题的标准解决方案。在
相关问题 更多 >
编程相关推荐