Is it possible to define a class constant inside an Enum?

后端 未结 5 975
感情败类
感情败类 2020-11-27 15:51

Python 3.4 introduces a new module enum, which adds an enumerated type to the language. The documentation for enum.Enum provides an example to demonstrate how i

5条回答
  •  被撕碎了的回忆
    2020-11-27 16:40

    TLDR; NO, it can not be done inside an Enum class.

    This said, as the other answers showed, there are ways to get such class owned values associated to an Enum (i.e. via class inheritance / mixins) but such values are not "defined .. inside an Enum".

提交回复
热议问题