Dec-15-2018, 05:44 AM
Hi
To get the output 'first' as the printed enum value that I want , I have to use 'value[0]' instead of 'value'.
TypeError: __str__ returned non-string (type tuple)
To get the output 'first' as the printed enum value that I want , I have to use 'value[0]' instead of 'value'.
from enum import Enum
class BadEnum(Enum):
def __str__(self):
return self.value[0]
FIRST = 'first',
SECOND = 'second'
print(BadEnum.FIRST)Is this an error in Python Enum code to use 'tuple' and not 'string'? If I use 'self.value' instead of 'self.value[0]', I get:TypeError: __str__ returned non-string (type tuple)
