迭代python 3中的枚举时,并不是所有元素都会出现

acu*_*ner 4 python enums python-3.x

在下面的代码,我分配b给功能fEnum.然而,当我遍历那个枚举时,b虽然我仍然可以通过它访问它E.b.有谁知道这里发生了什么?这只是一个错误吗?我正在使用python 3.5.1.

In [42]: from enum import Enum
In [43]: def f(): pass
In [44]: class E(Enum):
    ...:     a = 4
    ...:     b = f
    ...:     c = 5
    ...:
In [45]: list(E)
Out[45]: [<E.a: 4>, <E.c: 5>]
In [46]: E.b
Out[46]: <function __main__.f>
Run Code Online (Sandbox Code Playgroud)

Jos*_*Lee 9

描述符不会成为枚举的成员.如果你给出你的枚举行为,那些方法与值本身存在于同一个命名空间中,所以这是枚举将它们分开的唯一方法.