I have a Python dictionary with the following data:
Tmp={'Name1': [10.0, 20.0, 'Title1', 1], 'Name2': [5.0, 25.0, 'Title2', 2]}
I want to pass this to a C function, where the function is defined as:
struct CA { char *Keys; float *Values; char *Title; int Index; }; void myfunc (struct CA *in, int n);
On the Python side, I created an equivalent ctypes structure like:
class CA(ctypes.Structure): _fields_ = [("Keys", ctypes.POINTER(ctypes.c_char_p)), ("Values", ctypes.POINTER(ctypes.c_float)), ("Title", ctypes.POINTER(ctypes.c_char_p)), ("Index", ctypes.c_int)]
and created a CA array using:
CAarray = CA * 2
Now I want to assign Tmp to CAarray in a loop so that
k = Tmp.keys() for (j, _) in enumerate(k): CAarray[j].Keys = _ CAarray[j].Values = Tmp[_][:2] CAarray[j].Title = Tmp[_][2] CAarray[j].Index = Tmp[_][3]
I am struggling to get the syntax right and still have failed. Reference.
On the other hand, is there any / lib routine that can handle the mutual conversion between Python variables and ctypes variables?