How to get all values from python enum class?

user1159517 picture user1159517 · Apr 8, 2015 · Viewed 101.3k times · Source

I'm using Enum4 library to create an enum class as follows:

class Color(Enum):
    RED = 1
    BLUE = 2

I want to print [1, 2] as a list somewhere. How can I achieve this?

Answer

ozgur picture ozgur · Apr 8, 2015

You can do the following:

[e.value for e in Color]