Bit fields in python?

Kwan Lai Cheng laicheng_kwan at
Wed Sep 8 12:43:20 CEST 2010

Thanks everyone for all the suggestions! New to python, so reading up on the struct module & Construct library now, hope to get my problem fixed soon.
  ----- Original Message ----- 

  Bitfields are most commonly used for extreme space optimization - i.e. shoving several variables and flags with carefully limited ranges into a single work. In Python you rarely work this way (where such an optimization is warranted, Python isn't the best tool for the job). However, as in your use case, it is sometimes needed in Python in order to communicate with other devices over the network or some other link.

  In my work with Python and embedded devices I've found the construct library ( very useful. It allows to you very easily define complex formats for frames/messages on the bit and byte level. The idea is to use construct to encode and decode messages being sent to an embedded device. It works great.

  If you have further questions about this approach, feel free to ask.



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list