return tuple from C to python (extending python)

Farshid Lashkari no at spam.com
Wed Oct 25 02:05:49 CEST 2006


Simon Forman wrote:
> I have not done a great deal of extension work with python, however, I
> do not believe you can simply cast an int (or pointer to int, which is
> what you say dat is declared as, unless my C is /really/ rusty) to
> PyObject*.
> 
> I think you need to do something like Py_BuildValue("i", 123), but see
> http://docs.python.org/ext/buildValue.html for more info.

Simon is correct. You need to create a python object from your unsigned 
int. Try the following instead:

PyTuple_SET_ITEM(toRet, i, PyInt_FromLong(dat[i]) );

-Farshid



More information about the Python-list mailing list