Parsing Binary Structures; Is there a better way / What is your way?
Martin P. Hellwig
martin.hellwig at dcuktec.org
Wed Aug 5 13:05:08 EDT 2009
Jon Clements wrote:
<cut>
> IIRC (and I have my doubts) the BitVector module may be of use, but
> it's been about 3 years since I had to look at it. I think it used the
> C equiv. of short ints to do its work. Otherwise, maybe the array
> module, the struct module or even possibly ctypes.
>
> Not much use, but might give a few pointers.
>
> Jon.
I tried struct before (it seemed logical) but it didn't really do what I
expected:
>>> import struct
>>> struct.unpack('?','x')
(True,)
I expected a list like (False, True, True, True, True, False, False,
False). But it is (actually I hope) just an error of my side, so if
somebody knows how to achieve what I want, with this module, please
enlighten me :-)
The array module doesn't seem to have an option for boolean values.
BitVector does look very promising, but after peeking in the source it
does more or less the same as what I do with converting back and forth
of 'bitstrings'.
I haven't thought about using ctypes for this, excellent suggestion!
Thank you for your feedback.
--
MPH
http://blog.dcuktec.com
'If consumed, best digested with added seasoning to own preference.'
More information about the Python-list
mailing list