June 29th, 2004, 02:52 PM
Dictionary to Struct
At the moment, I am writing a Python module in C ( a wrapper around an API, to be more specific ). I have almost no experience with working in C, but I am managing to get by so far. However, I have run into a problem. Is there any way to easily convert a Python dictionary to a C struct?
Any help would be much appreciated!
You can create a C struct using the struct module (surprise surprise).
However a C struct is a fixed size, and a dictionary is a variable size, so there is no direct correspondence.
If you mean you have a dict object with an entry for each member of the struct, then it should be quite easy. Read the docs for the struct library module for more information.
Dave - The Developers' Coach