return tuple from C to python (extending python)

Kiran Kiran.Karra at gmail.com
Thu Oct 26 08:55:25 EDT 2006


Farshid Lashkari wrote:
> 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

That did the trick.  thanks guys both for your help!




More information about the Python-list mailing list