我们如何传递C结构到Python? [英] How can we pass a C structure to Python?
本文介绍了我们如何传递C结构到Python?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是一个新的在C和Python。这些天,我正在学习Python嵌入在C.由于我在C中调用Python函数,我想知道,怎样才能通过C结构到Python?
I'm a new in both C and Python. These days, I'm learning to embed Python in C. As I am calling Python functions from C, I'd like to know, how can we pass a C structure to Python?
非常感谢提前!
推荐答案
做的事情干净可能是的创建一个新类型和实施 tp_getattr
,要么返回结构的相应成员或提高取决于参数异常过去了。
The cleanest thing to do is probably to create a new type and implement tp_getattr
, either returning the appropriate member of the struct or raising an exception depending on the argument passed.
这篇关于我们如何传递C结构到Python?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文