[Python] How to define a variable in an __init__ function with a class method?

Discussão em 'Python' iniciado por Stack, Agosto 7, 2025.

  1. Stack

    Stack Membro Participativo

    class TextToNumbers():
    def __init__(self, number):
    self.text = str(number)
    self.chunks = parse_text_to_chunks(self.text)

    def parse_text_to_chunks(text_to_parse):
    #stuff


    This is an example of a class I'm building. I want it to define some variables with class methods on initialization. (at least I think that is what I want) I think if I talk about my end goal it is that I have a set of complex information that needs to be available about a class directly at initialization. How do I call a class method at initialization, to define a class variable?

    Continue reading...

Compartilhe esta Página