如何通过ctypes将列表列表(非空)从Python传递到C++
How to pass (non-empty) list of lists from Python to C++ via ctypes?
我有一些格式为的数据
data = [[1,1,1],[2,2,2],[3,3,3]]
如何通过ctypes将其传递给C++?
我可以单独传递每个列表,如下所示:
import ctypes
temp1 = [1,1,1]
temp2 = [2,2,2]
temp3 = [3,3,3]
list1 = (ctypes.c_int * 3)(*temp1) #NO IDEA WHAT THE * MEANS
list2 = (ctypes.c_int * 3)(*temp2)
list3 = (ctypes.c_int * 3)(*temp3)
但在那之后,如果我试图将所有这些列表附加到"数据"中。。。
data.append(list1)
data.append(list2)
data.append(list3)
data_final = (ctypes.?????? * 3)(*data)
我应该放什么类型的?????感谢
??????
应为ctypes.c_int * 3 * 3
data_final = (ctypes.c_int * 3 * 3)(*data)
[list(a) for a in data_final]
# --> [[1, 1, 1], [2, 2, 2], [3, 3, 3]]
为了记录,不要进行
data = []
data.append(list1)
data.append(list2)
data.append(list3)
这是python,不是c++,做
data = [list1, list2, list3]
见鬼,因为你只是想把它传给一个函数做
data_final = (ctypes.c_int * 3 * 3)(list1, list2, list3)
并且完全跳过CCD_ 3步骤
如果我在N x M
列表py_list
中有数据,我会进行
c_array = (c_types.c_int * M * N)(*[(c_types.c_int * M)(*lst) for lst in py_list])
相关文章:
- Pybind11:将元组列表从Python传递到C++
- 如何在C++中使用pybind11加载一个pickle python列表
- 替代在python中制作邻接列表与图形问题的字典?(如 C++ 中的 vector<vector<int&g
- C++未知长度字符串的数组,其行为类似于 Python 字符串列表
- 如何使用列表/数组在C++中实现 Python "... not in ..."?
- 在 c++ 中创建一个类似 python 的列表
- 如何通过ctypes将列表列表(非空)从Python传递到C++
- 在 DLL 中嵌入 Python:Py_DECREF列表对象时访问冲突读取位置
- 从 std::vector<double> 到 Python 列表的转换失败(提升 python)
- 使用 rangesv3 在 c++ 中模拟 python 风格的列表理解?
- 在C++中创建 python "列表"
- C - 将数字添加到列表中?(就像python)
- 将 std::list of structs 转换为 Python 列表
- 使用BOOST :: PYTHON返回裸露的类对象列表,这些对象是不可复制的
- 如何使用 Swig 将无符号字符* 转换为 Python 列表
- SWIG C++ to Python:生成 Python 列表的子类
- Python:我们应该如何编写一个函数来返回对象/列表和布尔标志
- 用eCmascript Regex验证Python列表索引语法
- 如何有效地将 2d python 列表馈送到 c++ 扩展模块
- 使用 Python API 获取 Maya 中的引用节点列表