Modules, Packages, Import

Doc: https://docs.python.org/fr/3/reference/import.html

https://towardsdatascience.com/learn-python-modules-and-packages-in-5-minutes-bbdfbf16484e

https://stackoverflow.com/questions/8953844/import-module-from-subfolder

add __init__.py to every subfolder you are importing from

Exemple 1

#/home/marc/test
├── # app  
│   ├── # controllers
│   │   ├── # a.py
│   │   │
│   │   │       class ControllerA:
│   │   │           def hello(self):
│   │   │               print("Hello, I'm Controller A")
│   │   │
│   │   └── # b.py
│   │
│   │           class ControllerB:
│   │               def hello(self):
│   │                   print("Hello, I'm Controller B")
│   │
│   ├── # main.py
│   │
│   │   from .controllers.a import ControllerA
│   │   from .controllers.b import ControllerB
│   │
│   │   class Application:
│   │       def __init__(self):
│   │           self.name = "Mauricette"
│   │
│   │       def show(self):
│   │           a = ControllerA()
│   │           a.hello()
│   │           b = ControllerB()
│   │           b.hello()
│   │
│   └── # __init__.py
│
│           from .main import Application
│    
│           app = Application()
│
└── # run.py
 
        from app import app
 
        if __name__ == "__main__":
            print(app.name)
            app.show()