export an array of floats to python

Peter Wuertz pwuertz at students.uni-mainz.de
Thu Feb 22 11:40:21 EST 2007


Hi,

I'm writing a C module for python, that accesses a special usb camera. 
This module is supposed to provide python with data (alot of data). Then 
SciPy is used to fit the data.

My question is, how to make python read from a C array? By reading the 
documentation, one could get the impression that PyBufferObjects do that 
job.

http://docs.python.org/api/bufferObjects.html

It says:
"Two examples of objects that support the buffer interface are strings 
and arrays."

Where this function looks promising:
"PyBuffer_FromMemory - Return a new read-only buffer object that reads 
from a specified location in memory, with a specified size."

All right, lets imagine I created a PyBufferObject from my float array 
in the C module, and passed it to python.

I dont know what to do with a BufferObject in python, I would like to 
"cast" it to a Array of the type float, but Arrays do not have that kind 
of function... they can only be constructed from files or lists.

Apart from creating these BufferObjects, there is no documentation about 
what to do with them :(

Thanks for your help!



More information about the Python-list mailing list