我想从Python应用程序调用一个C库.我不想包装整个API,只包装与我的 case 相关的函数和数据类型.在我看来,我有三个 Select :
I'm not sure whether 2) or 3) is the better choice. The advantage of 3) is that ctypes
is part of the standard library, and the resulting code would be pure Python – although I'm not sure how big that advantage actually is.
两种 Select 都有更多的优点/缺点吗?你推荐哪种方法?
Edit: Thanks for all your answers, they provide a good resource for anyone looking to do something similar. The decision, of course, is still to be made for the single case—there's no one "This is the right thing" sort of answer. For my own case, I'll probably go with ctypes, but I'm also looking forward to trying out Cython in some other project.
由于没有单一的真实答案,接受一个答案多少有些武断;我 Select 了FogleBird的答案,因为它提供了对ctypes的一些很好的见解,而且它目前也是投票率最高的答案.然而,我建议阅读所有答案,以获得一个良好的概述.
再次感谢您.