Outils pour utilisateurs

Outils du site


python:modules_packages_import

Modules, Packages, Import

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()
python/modules_packages_import.txt · Dernière modification: 2021/05/15 06:52 (modification externe)