return tuple from C to python (extending python)

Chetan pandyacus.xspam at xspam.sbcglobal.net
Tue Oct 24 21:15:20 EDT 2006


"Kiran" <Kiran.Karra at gmail.com> writes:

> PyObject* toRet;
> toRet = PyTuple_New(num_addr);
>
> then, in a for loop, i assign values to the tuple as follows:
>
> for ( i = 0; i < num_addr; i++ )
>     {
>         printf("%d\n", dat[i]);
>         PyTuple_SET_ITEM(toRet, i, (PyObject*)dat[i] );
>     }
> (dat is declared as follows: unsigned int* dat; )
>
> then, i say return toRet at the end of my C function.
>
> when I try to print the tuple in python, it says the memory address
> 0x.... could not be written, and I can see a part of the tuple
> printout, which is as follows:
> ( <nil>,
> then i get my error.
>
You could use PyInt_FromXXXX functions to convert dat[i] to PyInt



More information about the Python-list mailing list