python3 ctypes 的 结构体定义中,怎么引用自身?

川一八 2018-09-07 08:14:10
我这么使用时提示说“找不到Sentence_link”

```
class Sentence_link(ctypes.Structure):
_fields_= [("para_idx", ctypes.c_ulong), ("sent_idx", ctypes.c_ulong),("sent_init",ctypes.c_int),("msg_buff",ctypes.c_char_p), ("next",ctypes.POINTER(Sentence_link))]
```
```
_fields_= [("para_idx", ctypes.c_ulong), ("sent_idx", ctypes.c_ulong),("sent_init",ctypes.c_int),("msg_buff",ctypes.c_char_p), ("next",ctypes.POINTER(Sentence_link))]
NameError: name 'Sentence_link' is not defined

```
请问该如何引用自身?


...全文
1515 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
举世无双勇 2020-03-13
  • 打赏
  • 举报
回复
https://blog.csdn.net/nb_zsy/article/details/104836310
举世无双勇 2020-03-13
  • 打赏
  • 举报
回复
因为新的类 单元格在类语句本身中不可用。在ctypes中,我们可以 在类语句之后定义单元格类并设置_fields_属性 类似这样写 #重构struct list_head结构体 (+pass 定义的时候另起一行) class list_head(ctypes.Structure): pass list_head._fields_ = [("next",POINTER(list_head)),("prev",POINTER(list_head))]

24,860

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧