Trying to use an enum in Python 3.7.3, getting the following error. Already tried to install - and uninstall - enum34, but it still does not work. Did all the operations in a virtual environment (as the error shows).
Is there anything else I can do to fix this (except using another enum implementation as shown in this question)?
#enum import:
from enum import Enum
# enum definition:
class Status(Enum):
    on: 1
    off: 2
# enum utilisation (another class, same file):
self.status = Status.off
# error:
File "C:\dev\python\test\venv\lib\enum.py", line 349, in __getattr__
AttributeError(name) from None
AttributeError: off
                The correct syntax for defining an enum is:
class Status(Enum):
    on = 1
    off = 2
Not on: 1.
In your definition, use = to assign values to the attributes, not :.
# enum definition:
class Status(Enum):
    on = 1
    off = 2
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With