I never thought I needed to do this, but here I intend to use enums in python 2.7.
There is Barry flufl.enum , which PEP 435 says: "... was the reference implementation on which this PEP was originally based."
But there is also backport enum34 on pypi .
Both of these seem semi-official, and which one should be used in the new code?
βThere must be one obvious way to do this,β but this is a difficult topic for Google because there are dozens (hundreds?) Of manual implementations there. And python 3.4 enum is still a candidate for release.
I tried both flufl.enum.Enum and enum34.Enum , and the behavior is completely different - primarily the different semantics of __getitem__ . According to this comment by Martijn Pieters, backport was / was complicated as the implementation is based on the new __prepare__ function on the metaclass. I read this post and PEP as a whole.
python enums
wim
source share