3.4枚举应该使用UPPER_CASE_WITH_UNDERSCORES吗? [英] Should 3.4 enums use UPPER_CASE_WITH_UNDERSCORES?
问题描述
如文档所述,枚举是绑定到唯一的恒定值的一组符号名称(成员)。 PEP8 表示常量通常被命名为 UPPER_CASE
,我应该在Python 3.4 枚举中使用此符号吗?如果是,为什么文档中的示例使用 lower_case
?
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
?
推荐答案
更新
BDFL(仁慈的生命独裁者)说了,并且 枚举文档
已更改为反映所有大写成员名称。
The BDFL (Benevolent Dictator For Life) has spoken, and the Enum documentation
has changed to reflect all upper-case member names.
[previous]文档中的示例是小写字母,主要是因为Enum基于的一个已有模块之一使用了小写字母(或者至少是
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__)
有效地将所有膜
所以我想说哪种风格对您来说都更舒适-但要选择一种风格并保持一致。
So I would say whichever style feels more comfortable to you -- but pick a style and be consistent.
这篇关于3.4枚举应该使用UPPER_CASE_WITH_UNDERSCORES吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!