tl;dr What's a Pythonic (Py 3) way of specifying a large number of defined bit masks and constants? Use an Enum(s) or just have a load of consts as class variables? And the advantages/disadvantages?
Background
I'm porting C code to Python 3. In the C code there's a large number of defines which are used as bit masks:
#define ERR_1 = 0x8
#define ERR_2 = 0x2
#define ERR_4 = 0x100
...
I thought in Python a Pythonic way of having these would be by using an Enum
, I came across IntEnum
which means I don't have to use .value
everywhere like I would with a normal Enum
:
from enum import IntEnum
class Errors(IntEnum):
BROKEN = 0x8
FUBARED = 0x4
GIVEUP = 0x7
print(0xFF & Errors.BROKEN)
but it's still more verbose than just having print(0xFF & ERR_1)
which I could get if I had them all as consts.