3

我是 C 和 Python 的新手。这些天,我正在学习在 C 中嵌入 Python。当我从 C 中调用 Python 函数时,我想知道,我们如何将 C 结构传递给 Python?

提前非常感谢!

4

3 回答 3

2

这份关于扩展和/或嵌入 Python 的文档可能会帮助您入门

还有一个ctypes库可以动态加载本机 DLL 并在其中传入和传出类似 C 的结构(完全来自 Python 内部)。

于 2011-04-20T17:14:08.793 回答
2

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.

于 2011-04-20T17:16:07.743 回答
-1

这可能不是您想要的,但我们使用LCM在 c/c++、python、java 和 matlab 程序之间通过 udp 和多播共享 c 结构。这对于做机器人技术非常方便。

于 2011-05-03T22:24:01.197 回答