<div dir="ltr">random.choice and Enum interact poorly, because indexing an enum class doesn't work as choice expects:<br><br>>>> import enum, random<br>>>> class C(enum.Enum): a, b = 1, 2<br>...<br>>>> random.choice(C)<br>
<traceback...><br>KeyError: 1<br><br>Of course one can do `random.choice(list(C.__members__.values()))` but this feels a bit awkward.<br><br>The source for random.choice is<br><br>def choice(self, seq):<br>    """Choose a random element from a non-empty sequence."""<br>
    try:<br>        i = self._randbelow(len(seq))<br>    except ValueError:<br>        raise IndexError('Cannot choose from an empty sequence')<br>    return seq[i]<br><br>Adding seq = list(seq) should be enough to fix this.<br>
<br>Antony<br></div>