I asked this question in interpret an integer as enum flags but did not state the challenge as clearly as I should have. I am looking for how to take a pure integer, not an instance of a class based on Flags, and interpret the integer according to the definitions in the class.
Suppose I have a Flag enum like this:
From enum import Flag
class suspicion(Flag):
TOT_PCNT_LOW = 1
IND_PCNT_LOW = 2
IND_SCORE_LOW = 4
And suppose I have an integer that has bits set consistent with the definition, but is just an integer. It is ot an instance of the suspicion enumeration.
i == 3
How do I get a list of the names of the flags that correspond to the bits in the integer?
For example:
print(some_method(i)) # prints ["IND_PCNT_LOW", "TOT_PCNT_LOW"]