I have a ctypes structure.
class S1 (ctypes.Structure):
_fields_ = [
('A', ctypes.c_uint16 * 10),
('B', ctypes.c_uint32),
('C', ctypes.c_uint32) ]
if I have X=S1(), I would like to return a dictionary out of this object: Example, if I do something like: Y = X.getdict() or Y = getdict(X), then Y might look like:
{ 'A': [1,2,3,4,5,6,7,8,9,0],
'B': 56,
'C': 8986 }
Any help ?
Probably something like this:
As you can see, it works with numbers but it doesn’t work as nicely with arrays — you will have to take care of converting arrays to lists yourself. A more sophisticated version that tries to convert arrays is as follows:
If you have
numpyand want to be able to handle multidimensional C arrays, you should addimport numpy as npand change:to:
This will give you a nested list.