Passing python list from C to python

hartley hartley79 at gmail.com
Mon Jul 13 11:47:03 EDT 2009


I'm very new at wrapping Python/C, and I have run into some problems.

I have one python module that provides me with a list (provideBuffer
in provideBuff.py):

 Py_Initialize();
	pName = PyString_FromString("provideBuff");
	pModule = PyImport_Import(pName);

	pFunc = PyObject_GetAttrString(pModule,"provideBuffer");

	pValue = PyObject_CallObject(pFunc,NULL);

pValue is now a PyList - i've even verified this with:

int a = PyList_Check(pValue);
	printf("%d\n", a);

However, I want to send this PyList to another python module, but I
don't know how to do this. Initially I though I could just do like
above, only swapping NULL with pValue, but that is not working.

pName2 = PyString_FromString("C-embedding");
pModule2 = PyImport_Import(pName2);
pFunc2 = PyObject_GetAttrString(pModule2,"buff");
pValue2 = PyObject_CallObject(pFunc2,pValue);

pValue2 is now False! So i guess i cannot pass pValue as an argument
to PyObject_CallObject when i want to pass an python list as an
argument. But how must a go about to make this work?



More information about the Python-list mailing list