I do have a class with multiple methods in which I'd like to add constant values of instances of this class, to keep common used combinations handy.
class Text:
GREETING = Text('Hello')
LOREM = Text('Lorem ipsum dolor sit amen')
def __init__(self, text):
self.text = text
def double(self):
return f'{self.text}, {self.text}'
This doesn't work in that way (Undefined name 'Text'). I could declare the constants later on:
Text.GREETING = Text('Hello')
Text.LOREM = Text('Lorem ipsum dolor sit amen')
But that doesn't seem quite nice to me. I'd like to have it all inside of the class definition to be able to document everything nicely. Is there any other way possible?
enum?@classmethodthat adds those constants to the class, but you still have to call it manually after