Future-compatible enums in 2.7?

前端 未结 1 1270
面向向阳花
面向向阳花 2020-12-29 20:52

Many methods of implementing enums are shown in the answers to this question. However, PEP0435 is out now and describes how Enum and IntEnum will become official in Python 3

1条回答
  •  天命终不由人
    2020-12-29 21:39

    There is a backport of the PEP 435 enum module available on PyPI as enum34. The backport seems to be unofficial, however it is authored by Ethan Furman, who is a Python core committer and one of the co-authors of PEP 435.

    The backport is declared compatible with Python 2.4 and greater. Of course, under Python 2 there are a few, relatively minor, differences in behaviour, but from my preliminary exploration under Pyhon 2.7, I'd say that the level of forward compatibility is quite high.

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