[英]python ctypes array will not return properly
这不起作用:
def CopyExportVars(self, n_export):
export_array = (ctypes.c_double * n_export)()
self.dll_handle.vs_copy_export_vars(ctypes.cast(export_array, ctypes.POINTER(ctypes.c_double)))
return export_array().contents
我收到此错误( n_export
为3):
TypeError: 'c_double_Array_3' object is not callable
错误是不言而喻的。 export_array
不是可调用的对象,但是您尝试在函数的最后一行中调用它。 另外,您尝试使用与指针相关的接口('.contents')从数组中检索值,而不是从数组中获取指针。
使它工作的最简单方法是将ctypes
结果数组转换为纯Python对象并返回它:
def CopyExportVars(self, n_export):
export_array = (ctypes.c_double * n_export)()
self.dll_handle.vs_copy_export_vars(ctypes.cast(export_array, ctypes.POINTER(ctypes.c_double)))
return list(export_array)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.