How to export a C array to Python -
i have file.cc contains array of doubles values, seen here:
double values[][4] = { { 0.1234, +0.5678, 0.1222, 0.9683 }, { 0.1631, +0.4678, 0.2122, 0.6643 }, { 0.1332, +0.5678, 0.1322, 0.1683 }, { 0.1636, +0.7678, 0.7122, 0.6283 } ... continue }
how can export these values python list?
i cannot touch these files because belong external library, subject modification. exactly, want able update library without affecting code.
this pretty answered in this other post.
but add bit here. need define type use in_dll
method.
from example made values in values
. hope have idea how big or can find out other vars in library, otherwise seg fault waiting happen.
import ctypes lib = ctypes.cdll('so.so') da = ctypes.c_double*4*4 da.in_dll(lib, "values")[0][0] # 0.1234 da.in_dll(lib, "values")[0][1] # 0.5678 da.in_dll(lib, "values")[0][2] # 0.1222
from here loop on them reading list.
Comments
Post a Comment