开发者

How to use float ** from C in Python?

after having no success with my question on How to use float ** in Python with Swig?, I started thinking that swig might not be the weapon of choice. I need bindings for some c functions. One of these functions takes a float**. What would you recomend? Ctypes?

Interface file:

extern int read_data(const char *file,int *n_,int *m_,float **data_,int **clas开发者_如何学Goses_);


I've used ctypes for several projects now and have been quite happy with the results. I don't think I've personally needed a pointer-to-pointer wrapper yet but, in theory, you should be able to do the following:

from ctypes import *

your_dll = cdll.LoadLibrary("your_dll.dll")

PFloat = POINTER(c_float)
PInt   = POINTER(c_int)

p_data    = PFloat()
p_classes = PInt()
buff      = create_string_buffer(1024)
n1        = c_int( 0 )
n2        = c_int( 0 )

ret = your_dll.read_data( buff, byref(n1), byref(n2), byref(p_data), byref(p_classes) )

print('Data:    ', p_data.contents)
print('Classes: ', p_classes.contents)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜