How to print combined Flag in the same way as name property
问题 In Python, you can use the Flag class to represent combinations of values. class Color(Flag): Red = auto() Green = auto() Blue = auto() White = Red | Green | Blue These implicitly convert to strings so you can print them. >>> print(Color.Red, Color.White, Color.Red|Color.Green) Color.Red Color.White Color.Green|Red The name property gives you can even nicer way to print, but it doesn't work for unnamed combined values. >>> print(Color.Red.name, Color.White.name, (Color.Red|Color.Green).name)