Never thought I'd need to do this, but here I am intending to use enums in python 2.7.
There is Barry's flufl.enum which PEP 435 says "...was the reference implementation upon which this PEP was originally based".
But there is also a backport enum34 on pypi.
These both seem semi-official, so which one should I use in new code?
"There should be one obvious way to do it", but it's a hard topic to google for because there are dozens (hundreds?) of hand-rolled implementations out there. And the python 3.4 enum is still just a release candidate.
I've tried out both flufl.enum.Enum
and enum34.Enum
, and the behaviour is quite different - most notably the differing semantics of __getitem__
. According to this comment by Martijn Pieters, backport is/was challenging because implementation relies on the new __prepare__
function on the metaclass. I've read this post and the PEP in entirety.