'Adding non-integer member values to IntEnum in Python3
I have roughly the following:
class Foo(IntEnum):
a = 0
b = auto()
c = auto()
strings = ["Alpha", "Beta", "Charlie"]
def __str__(self):
return Foo.strings[self]
However, this raises:
TypeError: int() argument must be a string, a bytes-like object or a number, not 'EnumMeta'
I need to have additional data inside my Foo class, but it appears that Python doesn't like that.
Is there something I'm doing incorrectly, or is there a better way to do this? I'm used to Enum Classes in C++.
Solution 1:[1]
After a fair bit of digging, I found a way to get the proper behavior that I was looking for. Firstly, I had to use Enum instead of IntEnum. Secondly, I had to upgrade to Python3.11 and use the nonmember function to mark things that are not enumerable.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | user852541 |
