ctypes - pointer to array of structs?

skip at pobox.com skip at pobox.com
Fri Jan 4 00:10:32 CET 2008

(Is this the right place to ask ctypes questions?  There's a mailing list
but the last post to it seems to have been in November 2006.)

Using ctypes I reference a structure which contains a pointer to an array of
another structure:

    class SYMBOL(Structure):
        _fields_ = [("symbol", c_char_p),
                    ("num", c_int),
                    ("units", c_int),
                    ("baseprice", c_int),
                    ("active", c_int)]

    class TABLE(Structure):
        _fields_ = [("map", SYMBOL_PTR),
                    ("nsymbols", c_uint),

Effectively, TABLE.map is an array of TABLE.nsymbols SYMBOLS.  How to I
reference elements in that array?  In C I would just treat TABLE.map like an
array and index into it (for i=0; i< TABLE.nsymbols; i++) ...).  This is
data returned from a C library, not something I'm building in Python to pass
into C.



More information about the Python-list mailing list