[Tutor] Dealing with bitfields in Python

Kent Johnson kent37 at tds.net
Sun Aug 30 20:29:30 CEST 2009


On Sun, Aug 30, 2009 at 11:59 AM, Skipper Seabold<jsseabold at gmail.com> wrote:
> Hello all,
>
> Fair warning, I didn't know what a bitfield was a few hours ago.
>
> I am working with a program via the dbus module and I am wondering if
> there is built-in support to deal with bitfields in Python.  I query
> my application and it returns a bitfield 119.  The bitfield "key" is
>
> NONE                  = 0,
> CAN_GO_NEXT           = 1 << 0,
> CAN_GO_PREV           = 1 << 1,
> CAN_PAUSE             = 1 << 2,
> CAN_PLAY              = 1 << 3,
> CAN_SEEK              = 1 << 4,
> CAN_PROVIDE_METADATA  = 1 << 5,
> CAN_HAS_TRACKLIST     = 1 << 6

If you have many such fields you might be interested in Construct:
http://construct.wikispaces.com/

See for example
http://construct.wikispaces.com/tut-bitwise

Disclaimer - I've never used Construct myself. It looks handy though...

Kent


More information about the Tutor mailing list