本文介绍了如何使用float **在Python与痛饮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我写痛饮绑定某些C函数。其中的一个功能,需要一个浮动*的。我已经使用 cpointer.i ,在正常的指针,看着 carrays.i ,但我没有找到一个方法来声明一个浮动* 的。你有什么建议?接口文件:   EXTERN INT的read_data(为const char  *文件,为int * N_,为int * M_,浮** data_中的数据,诠释**类_); 解决方案 这答案是一至一个相关的问题Framester公布关于使用而不是痛饮ctypes的一个重新发布。我在这里包含它情况下,任何网络搜索打开了一个链接到他原来的问题。  我用ctypes的多个项目  现在已经与很高兴  结果。我不认为我个人  需要一个指针到指针包装  然而,但在理论上,你应该能够  做到以下几点: 从ctypes的导入*your_dll = cdll.LoadLibrary(your_dll.dll)PFloat =指针(c_float)品脱=指针(c_int的)P_DATA = PFloat()p_classes =品脱()BUFF = create_string_buffer(1024)N1 = c_int的(0)N2 = c_int的(0)RET = your_dll.read_data(BUFF,按地址(N1),按地址(N2),按地址(P_DATA),按地址(p_classes))打印(数据:,p_data.contents)打印(类:,p_classes.contents) I am writing swig bindings for some c functions. One of these functions takes a float*. I am already using cpointer.i for the normal pointers and looked into carrays.i, but I did not find a way to declare a float*. What do you recommend?interface file: extern int read_data(const char *file,int *n_,int *m_,float **data_,int **classes_); 解决方案 This answer is a repost of one to a related question Framester posted about using ctypes instead of swig. I've included it here in case any web-searches turn up a link to his original question. 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) 这篇关于如何使用float **在Python与痛饮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-15 04:42