1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Rep Power

    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!

  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    London, England
    Rep Power
    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

IMN logo majestic logo threadwatch logo seochat tools logo