I want to remove underscores in enum name but this code leads to recursion error, how to fix it efficiently?
from enum import Enum
class A(Enum):
ABC = '0'
OTC = '1'
_1T = '2'
@property
def name(self) -> str:
return self.name.replace('_', '')
I came up with this which works:
return self.__dict__['_name_'].replace('_', '')
Is there any other way?
>Solution :
Try changing:
return self.name.replace('_', '')
to:
return self.__dict__['_name_'].replace('_', '')