Search code examples
pythonwxpython

Call main methods from a outside module in python


I am making a GUI with the wxPython Libraries. I have some modules. The application beggins with a main function that call to a Main Controller. Like this:

from controller.mainController import MainController

if __name__ == '__main__':

    createGUI()

def createGUI():
    """
    Create the GUI
    """
    app = wx.App(False)
    host = MainController(app)
    app.MainLoop()

def readTerminal():
    terminal = consola.Console()
    try:
        terminal.cmdloop("Hola!")
        terminal.cmdloop("Fallo en la linea dos")
    except KeyboardInterrupt:
        terminal.do_quit(None)

I want to call readTerminal() function from another module. The modules are writing in different files. What can I do that?


Solution

  • If both the main module and other modules need to call readTerminal, then that function should be put into a common module that they can both import from. I usually have a controller module or a utility module where I can keep functions like that.