C++调用python,该如何处理

C++调用python
我现在有一个Python写的函数,需要向其传递一个嵌套列表,类似 ([[1,0,1],[1,1,0],[-1,2,2]]这样,不知道怎么从C++中创建相应的对象传递过去,假设C++中数据存放在一个二维数组中 arr[n][3],谢谢!
------解决思路----------------------
python c/api 很蛋疼的,不如直接传字符串,用eval执行返回

>>> arr = eval("[[1,0,1],[1,1,0],[-1,2,2]]")
>>> arr
[[1, 0, 1], [1, 1, 0], [-1, 2, 2]]
>>> len(arr)
3
>>> 

------解决思路----------------------
C++之python函数调用 


你也可以将参数写入文本,然后再调用python函数提取执行,避免构建复杂的PyObj参数

------解决思路----------------------
#构建最终列表
PyObject* pList = PyList_New(3);
#构建子列表1
PyObject* pList1= PyList_New(3); #[1,0,1]
PyList_SetItem(pList1,0, Py_BuildValue("i",1));
PyList_SetItem(pList1,1, Py_BuildValue("i",0));
PyList_SetItem(pList1,2, Py_BuildValue("i",1));
#构建子列表2
PyObject* pList2= PyList_New(3); #[1,1,0],
PyList_SetItem(pList2,0, Py_BuildValue("i",1));
PyList_SetItem(pList2,1, Py_BuildValue("i",1));
PyList_SetItem(pList2,2, Py_BuildValue("i",0));
#构建子列表3
PyObject* pList3= PyList_New(3); #[-1,2,2]
PyList_SetItem(pList3,0, Py_BuildValue("i",-1));
PyList_SetItem(pList3,1, Py_BuildValue("i",2));
PyList_SetItem(pList3,2, Py_BuildValue("i",2));
#将子列表嵌套
PyList_SetItem(pList ,0, pList1);
PyList_SetItem(pList,1, pList2);
PyList_SetItem(pList,2, pList3);

//函数调用
pRetVal = PyEval_CallObject(pFunc,pList );

ps:楼主根据需求自己整成循环呗。