How to access C structures

Mark Tolonen metolone+gmane at gmail.com
Fri Apr 17 00:07:50 EDT 2009


"Chris Helck" <Chris.Helck at us.icap.com> wrote in message 
news:6DB873C2999F7547AD0D1C0E6F0C89D70428579A at USPSEXCHS1.us.icap.com...
> I have a couple dozen C structures that define binary file records. I
> need to read the file and access the records. I need to do this very
> efficiantly.
>
> I am aware of the Python struct class, but the C structures contain
> arrays of nested structures and I'm not sure if Python struct can handle
> it. I am willing to give up portability for speed. I will run the Python
> program on the same machine that the file was created on.
>
> Is there some way to directly expose a C struct to Python?

Check out the ctypes library.

-Mark





More information about the Python-list mailing list