[英]Is there a reason why Python's ctypes.CDLL cannot automatically generate restype and argtypes from C header files?
For example, it would be nice to be able to do this: 例如,能够这样做会很高兴:
from ctypes import CDLL
mylib = CDLL('/my/path/mylib.so',header='/some/path/mylib.h')
instead of 代替
from ctypes import *
mylib = CDLL('/my/path/mylib.so')
mylib.f.restype = c_double
mylib.f.argtypes = [c_double, c_double]
mylib.g.restype = c_int
mylib.g.argtypes = [c_double, c_int]
My experience with python suggests that either something very close to this has been done already and I just haven't been able to find it, or that there is a good reason not to. 我对python的经验表明,已经完成了与此非常接近的事情并且我无法找到它,或者有充分的理由不这样做。 Are either of these the case? 这些都是这种情况吗?
I asked myself the same question and before I traveled down that road too far, I ran into ctypesgen: 我问自己同样的问题,在我走过这条路太远之前,我遇到了ctypesgen:
http://code.google.com/p/ctypesgen/ http://code.google.com/p/ctypesgen/
It will handle all of this for you, although you will need to do a little learning up front. 虽然你需要先做一点学习,但它会为你处理所有这些。 We use ctypesgen to generate one version of the Python bindings for the Subversion bindings. 我们使用ctypesgen为Subversion绑定生成一个版本的Python绑定。 It works very well. 它工作得很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.