Reading struct with structs

Alex Martelli aleaxit at
Sat Oct 16 12:17:33 CEST 2004

Baillargeon, Sonny <Sonny.Baillargeon at> wrote:

> I am trying to read in a C struct file that contains sub-structs as part
> as the data definition.  For example:
>       int     a       /* 4 bytes */
>       int_t   b       /* custom struct */
>       blah_t  c       /* custom struct */
>       bing_t  d       /* custom struct */
> The custom structs are arbitrary.  The struct module only allows me to
> have strict C datatypes.  How can I read in a struct recursively given I
> have to feed the struct.unpack?

You need to know how the various "custom structs" are made, in detail --
if you don't it's impossible to read that file, of course.  Now, just
insert the formatstring for the various fields of each "custom struct"
in place of the "custom struct" in the overall formatstring.


More information about the Python-list mailing list