枚举的迭代顺序是确定性的吗?
Is iteration order over an enum deterministic?
我正在使用 aenum
库。
from aenum import Enum as Aenum
class Availability(Aenum):
_init_ = "value string"
PART_TIME = 1, "Part-Time"
FULL_TIME = 2, "Full-Time"
BOTH = 3, "Both"
def __str__(self):
return self.string
for value, string in Availability:
print(value)
print(string)
从经验上看,它似乎是按照定义的顺序进行的,但我很好奇这是否得到保证。
aenum.Enum
是 described 和
a Python stdlib Enum-compatible data type
并且标准库 enum.Enum
是 documented 作为
Enumerations support iteration, in definition order
来自 Github 上的 documentation:
Enumerations support iteration. In Python 3.x definition order is used; in Python 2.x the definition order is not available, but class attribute _order_
is supported; otherwise, value order is used if posible, otherwise alphabetical name order is used.
我正在使用 aenum
库。
from aenum import Enum as Aenum
class Availability(Aenum):
_init_ = "value string"
PART_TIME = 1, "Part-Time"
FULL_TIME = 2, "Full-Time"
BOTH = 3, "Both"
def __str__(self):
return self.string
for value, string in Availability:
print(value)
print(string)
从经验上看,它似乎是按照定义的顺序进行的,但我很好奇这是否得到保证。
aenum.Enum
是 described 和
a Python stdlib Enum-compatible data type
并且标准库 enum.Enum
是 documented 作为
Enumerations support iteration, in definition order
来自 Github 上的 documentation:
Enumerations support iteration. In Python 3.x definition order is used; in Python 2.x the definition order is not available, but class attribute
_order_
is supported; otherwise, value order is used if posible, otherwise alphabetical name order is used.