Passing pointer to array from C to Python..and modifying same array in python?

JW jkpangtang at yahoo.com
Fri Jul 11 17:06:10 EDT 2003


Hi,


Below is a description of what I would like to do. Would someone tell
me if it is possible and if so, how?

I have an array (presumably 'large') that is mallocced in a C function
and its
values are initialized in that same function.
I would like to pass just the pointer to the beginning of the array
from this C function to a Pyton function.
Then the python method can individually access and MODIFY individual
members of the array.
After the call to the python method, the C function will see any
changes to the array.

Can this be done?
I know how to create a PyTuple_New and change each member of the C
array into a PyObject, then add all thos PyObjects to the Tuple,
before passing that PyTyple from C to Python, but this seems slow.

Thanks in advance for your help.




More information about the Python-list mailing list