Importing a class to another class in python
Question: I am trying to learn python i tried to import a class in another class but it
is not working

`Application.py`:

    
    
    class Application:
    
        def example(self):
            return "i am from Application class"
    

`Main.py`

    
    
    class Main:
    
        def main():
            application = Application()
            application.example()
    
    if __name__ == "__main__":
        Main.main()
    

This gives me :

    
    
    File "Main.py", line 11, in <module>
        Main.main()
    TypeError: unbound method main() must be called with Main instance as first argument (got nothing instead)
    


Answer: You should instantiate your Main class first.

    
    
    if __name__ == '__main__':
        myMain = Main()
        myMain.main()
    

But this will give you another error:

> TypeError: main() takes no arguments (1 given)

There are two ways to fix this. Either make Main.main take one argument:

    
    
    class Main:
        def main(self):
            application = Application()
            application.example()
    

or make Main.main a static method. In which case you don't have to instantiate
your Main class:

    
    
    class Main:
        @staticmethod
        def main():
            application = Application()
            application.example()
    
    if __name__ == "__main__":
        Main.main()
    

