in the code below, i assign b
to function f
in an Enum
. when i iterate through that enum, however, b
does not appear, although i can still access it via E.b
. does anyone know what's going on here? is this just a bug? i'm using 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>
Descriptors don't become members of the enumeration. If you give your enum behavior, those methods live in the same namespace as the values themselves, so this is the only way for enum to tell them apart.
_EnumDict.__setitem__
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With