Python 3.11+enumfunction
enum.show_flag_values()
flags
Breaks an integer flag value into powers of two: show_flag_values(13) gives [1, 4, 8]. Helps see which bits make up a flag.
Syntax
enum.show_flag_values(value)
enum's own error messages point to this function: with @verify(NAMED_FLAGS) the error says “use enum.show_flag_values(value) for details”. It takes an int (or a flag value) and returns the list of individual bits in ascending order, which shows which bit has no named Flag member. A negative number does not give an empty list; it raises ValueError.
Examples
import enum
print(enum.show_flag_values(13)) # → [1, 4, 8]
class Perm(enum.IntFlag):
R = 4
W = 2
X = 1
print(enum.show_flag_values(Perm.R | Perm.X)) # → [1, 4]
See also
Open in the full glossarydocs.python.orgReport an inaccuracy