In my program (written in Python 3.4) I have a variable which contains various flags, so for example:
FLAG_ONE = 0b1
FLAG_TWO = 0b10
FLAG_THREE = 0b100
status = FLAG_ONE | FLAG_TWO | FLAG_THREE
Setting another flag can easily be done with
status |= FLAG_FOUR
But what if I explicitly want to clear a flag? I'd do
status &= ~FLAG_THREE
Is this approach safe? As the size of an integer in Python is not defined, what if status
and FLAG_THREE
differ in size?
(status
needs to be a bit field because I need this value for a hardware protocol.)