How to fix Python Enum - AttributeError(name) from None error?

后端 未结 2 425
执念已碎
执念已碎 2021-01-21 09:11

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 vi

相关标签:
2条回答
  • 2021-01-21 09:22

    In your definition, use = to assign values to the attributes, not :.

    # enum definition:
    class Status(Enum):
        on = 1
        off = 2
    
    0 讨论(0)
  • 2021-01-21 09:25

    The correct syntax for defining an enum is:

    class Status(Enum):
        on = 1
        off = 2
    

    Not on: 1.

    0 讨论(0)
提交回复
热议问题