I use ctypes to access a file reading C function in python. As the read data is huge and unknown in size I use **float
in C .
int read_file(const char *file,int *n_,int *m_,float **data_) {...}
The functions mallocs
an 2d array, called data
, of the appropriate size, here n
and m
, and copies the values to the referenced ones. See following snippet:
*data_ = data;
*n_ = n;
*m_ = m;
I access this function with the following python code:
p_data=POINTER(c_float)
n=c_int(0)
m=c_int(0)
filename='datasets/usps'
read_file(filename,byref(n),byref(m),byref(p_data))
Afterwards I try to acces p_data
using contents
, but I get only a single float value.
p_data.contents
c_float(-1.0)
My question is: How can I access data
in python?
What do you recommended? Please don't hesitate to point out if I left something unclear!