I have a MVC project and I would to import my module like that:
import projet
view = projet.view()
controller = projet.controller()
model = project.model()
but, I'd like that controller(), model() and view() are in different files. How to do a module (project) but with different file in without import the other files after?
Create directory named project
, create file __init__.py
in this dir, put there code:
from view import *
from controller import *
from model import *
To the same dir put your view.py
, controller.py
, model.py
When you do
import project
all other imports would be done automatically (from __init__.py
). This is called packages (directory project
will become package name, packages are detected by existence of __init__.py
).
Further reading: http://www.network-theory.co.uk/docs/pytut/Packages.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With