Should 3.4 enums use UPPER_CASE_WITH_UNDERSCORES?

cdonts picture cdonts · Jan 26, 2014 · Viewed 8.7k times · Source

As the documentation says, an enumeration is a set of symbolic names (members) bound to unique, constant values. The PEP8 says that constants are usually named as UPPER_CASE, should I use this notation in Python 3.4 enums? If yes, why the examples in the docs are using lower_case?

Answer

Ethan Furman picture Ethan Furman · Jan 26, 2014

Update

The BDFL (Benevolent Dictator For Life) has spoken, and the Enum documentation has changed to reflect all upper-case member names.


The examples in the [previous] docs are lower-case primarily because one of the preexisting modules that Enum was based on used lower-case (or at least its author did ;).

My usage of enum has usually been something along the lines of:

class SomeEnum(Enum):
    ... = 1
    ... = 2
    ... = 3
globals().update(SomeEnum.__members__)

which effectively puts all the members in the module namespace.

So I would say whichever style feels more comfortable to you -- but pick a style and be consistent.