Bit fields in python?

John Nagle nagle at animats.com
Tue Sep 7 15:13:41 EDT 2010


On 9/6/2010 11:55 PM, Stefan Behnel wrote:
> Kwan Lai Cheng, 07.09.2010 06:06:
>> I'm trying to rewrite a c program in python& encountered several
>> problems. I have some data structures in my c program like below:
>>
def __init__(self, size=0)
>>
>> Any equivalent for c data structures& bit fields in python?
>
> If you can tell us what these structs are being used for in the original
> C code, we might be able to point you to a suitable way to implement the
> same thing efficiently in Python.

     Python has the "struct" module for formatting binary data.

http://docs.python.org/library/struct.html

     But it doesn't handle bit fields.  Its lowest resolution is
one byte.

				John Nagle



More information about the Python-list mailing list