I Have this piece of code :
class FileType(Enum):
BASIC = 0
BASIC_CORRUPTED = 1
BASIC_SHITTY_END = 2
MIMIKATZ = 3
HASHCAT = 4
def __eq__(self, v):
"""
Override == in order to make `FileType.BASIC == 0` equals to True, etc.
"""
return self.value == v if isinstance(v, int) else self.value == v.value
I wonder what I should add if I want to perform this: random_array[FileType.MIMIKATZ]
. Currently, Python3 tells me TypeError: list indices must be integers or slices, not FileType
Your class should inherit from
IntEnum
instead, this supports integer like behaviour. From the docs,You can now use an enum constant to index your list,