Skip to content

About

bitflags for python, both 2 and 3.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

bitflags-python

bitflags for both python 2 and python 3.

Quick start

First, you have to define your bits, starts from bit 0, one by one:

>>> from bitflags import BitFlags
>>> class TextStyle(BitFlags):
...     names = (
...         'bold',
...         'italic',
...         'underline',
...     )
>>>

Then, you've got all bit masks, with same name but in uppercase:

>>> TextStyle.BOLD
TextStyle(bits=1)
>>> TextStyle.ITALIC
TextStyle(bits=2)
>>> TextStyle.UNDERLINE
TextStyle(bits=4)

You can combinate different masks to make what you want:

>> my_style = TextStyle.BOLD | TextStyle.UNDERLINE
>>> my_style
TextStyle(bits=5)

You can tell whether specific bit is set:

>>> my_style.is_bold
True
>>> my_style.is_italic
False
>>> my_style.is_underline
True

Also, you can get value of given bit: