1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] How do I call a class method from another file in Python?

Discussão em 'Python' iniciado por Stack, Setembro 2, 2025.

  1. Stack

    Stack Membro Participativo

    I'm learning Python and have two files in the same directory.

    printer.py

    class Printer(object):
    def __init__(self):
    self.message = 'yo'

    def printMessage(self):
    print self.message

    if __name__ == "__main__":
    printer = Printer()
    printer.printMessage()


    How do I call the printMessage(self) method from another file, example.py in the same directory? I thought this answer was close, but it shows how to call a class method from another class within the same file.

    Continue reading...

Compartilhe esta Página