1

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++.

2
  • You are trying to do something along the lines of strings[Foo Object] while python is expecting strings[index as int, 0, 1 or 2] Commented May 14, 2022 at 23:51
  • @BijayRegmi line 1 is what's throwing the error though Commented May 14, 2022 at 23:57

1 Answer 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.

Sign up to request clarification or add additional context in comments.

1 Comment

3.11 is still in beta. :-) I'm glad the additions are working for you. And yes, the problem was because it was trying to turn your list of strings into an integer. Using nonmember should allow you to use IntEnum, though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.