Why is the following attribute not found in Enum?

I am using Python 2.7.5 and I have set Enum as

pip install Enum

I wrote out the following code to validate an Enum.

from enum import Enum
class Color(Enum):
  red = 'Hello'
  blue = 'Trello'
  green = 'Yello'

for name, attr in Color.__members__.items():
  print(attr.value)

      

This tells me the error.

AttributeError: type object 'Color' has no attribute '__members__'

...

Why can't python get it __members__

?

+3


source to share


2 answers


You are misleading enum

with enum

. They have a lot in common, but they are not the same thing. In particular, the attribute you are looking for does not exist.



+1


source


You need to use enum34 backport :



pip install enum34

      

+4


source







All Articles