Python的互操作性Ç [英] Python C interoperability

查看:134
本文介绍了Python的互操作性Ç的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想现有的C(纯C即没有C ++)库包装成Python的,这样我可以从Python脚本调用它。其中各种可用的(C API,SWIG等)中的方法是最合适的?

I wish to wrap an existing C (pure C that is. No C++) library into Python so that I can call it from Python scripts. Which approach among the various available (C Api, SWIG etc.) would be the most suitable?

推荐答案

去与ctypes的,它是标准发行版的一部分,而且运作非常良好。
基本上你可以用在Python类,以及函数C结构和类型。某些类型和功能已经被库中提供。

go with Ctypes, it is part of standard distribution and works very well. basically you can wrap C structures and types in python classes, as well as functions. Some types and functionality is already provided by library.

ctypes的

警告夫妇虽然:通过三重指针C例程并不明显(如果有),我无法得到它与Linux上的静态库工作,DLL和共享对象都很好

couple caveats though: passing triple pointers to C routines is not obvious (if you have to), and I could not get it to work with static libraries on Linux, DLL and shared objects are fine.

这篇关于Python的互操作性Ç的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆