Python and C, arrays

John Fisher jfisher at are.berkeley.edu
Fri Jun 11 22:17:18 CEST 1999


Hey folks,

I've run into a problem with a module I'm writing in C.  Basically, I
need to be able to convert Python tuples or lists (it's unimportant
which) into C arrays.  I know at compile-time the type of the array (and
that the tuple or list will be homogeneous, and of compatible type), but
I don't know the size.

I then need to find a way to take a C array and stuff it back into a
Python tuple or list.  I have some ideas involving using "stack-like"
lists or tuples in Python, with a "pop" function which I could call from
C, repeated in a loop to get everything.  But this seems overly complex,
and indeed like it has the potential to become truly hideous.

I would imagine these two tasks are actually quite common.  Is there
some simpler way to do either?  Dare I hope that PyArg_ParseTuple and
Py_BuildValue can do it?

Thanks,
John


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




More information about the Python-list mailing list