ctypes: Get full contents of character array

overdrigzed at gmail.com overdrigzed at gmail.com
Sat Sep 13 01:38:12 CEST 2008


Hello!

I wanted to get the full contents of a character array stored in a
struct, i.e.
_fields_ = [...("array", c_char * 12)...]
however, ctypes seems to try to return struct.array as a Python string
rather than a character array, and stops as soon as it encounters a
null within the character array.

I ended up having to define a dummy struct
class dummystruct(Structure):
    _fields_ = []

and declare array as:
("array", dummystruct)

then use string_at(byref(struct.array), 12).

Is this really the best way of doing it? Is there no better way to
work around ctypes 'guess what you want' behaviour?

Thanks in advance,
Rodrigo



More information about the Python-list mailing list