Ceci est une ancienne révision du document !
Doc: https://docs.python.org/fr/3/reference/import.html
https://towardsdatascience.com/learn-python-modules-and-packages-in-5-minutes-bbdfbf16484e
/home/marc/test ├── app │ ├── controllers │ │ ├── a.py │ │ └── b.py │ ├── services │ │ └── ... │ ├── __init__.py │ └── main.py └── run.py
from app import app if __name__ == "__main__": print(app.name) app.show()
from .main import Application app = Application()
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()
class ControllerA: def hello(self): print("Hello, I'm Controller A")
class ControllerB: def hello(self): print("Hello, I'm Controller B")
#/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") │ ├── # __init__.py │ │ │ │ from .main import Application │ │ │ │ app = Application() │ │ │ └── # 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() │ └── # run.py from app import app if __name__ == "__main__": print(app.name) app.show()