Store python returned array in c++ array

Hi guys,

I'm writing a c++ code to call a python function and the returned array from the python function will be store in an array in c++.I'm able to call the python function in c++ but I couldn't store the returned array for further process.Below is my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
int main(int argc, char *argv[])
{
	int i;
	PyObject *pName, *pModule, *pDict, *pFunc, *pArgs, *pValue;

	if (argc < 3) 
	{
		printf("Usage: exe_name python_source function_name\n");
		return 1;
	}

	// Initialize the Python Interpreter
	Py_Initialize();

	// Build the name object
	pName = PyString_FromString(argv[1]);

	// Load the module object
	pModule = PyImport_Import(pName);

	// pDict is a borrowed reference 
	pDict = PyModule_GetDict(pModule);

	// pFunc is also a borrowed reference 
	pFunc = PyDict_GetItemString(pDict, argv[2]);

        pValue = PyObject_CallObject(pFunc, NULL);
        if (pValue != NULL) 
		{
			printf("Return of call : %d\n", PyInt_AsLong(pValue));
			PyErr_Print();
			Py_DECREF(pValue);
		}
		else 
		{
			PyErr_Print();
		}


Hope you guys can help me and give me some hints.Thank you so much
Topic archived. No new replies allowed.