Interconvert a ctypes.Structure to/from a binary string?

Uwe Schmitt rocksportrocker at googlemail.com
Sat Aug 2 07:07:35 EDT 2008


On 2 Aug., 08:35, Andrew Lentvorski <bs... at allcaps.org> wrote:
> Basically, I'd like to use the ctypes module as a much more descriptive
> "struct" module.
>
> Is there a way to take a ctypes.Structure-based class and convert it
> to/from a binary string?
>
> Thanks,
> -a

My first idea was :

   from ctypes import *
   from pickle import *

   class T(Structure): pass

   print dumps(T())

which raises an TypeError, "abstract class".

And then I found

   http://osdir.com/ml/python.ctypes/2006-03/msg00009.html

Greetings, Uwe




More information about the Python-list mailing list