0

I am writing an application that has a lot of modules. In my entry-point module i need to import a lot of these modules to build my main GUI window and connect all the necessary MVP-parts. Currently i have something like this:

from project.model.model1 import Model1
from project.model.model2 import Model2
...
from project.view.view1 import View1
...
from project.presenter.presenter1 import Presenter1
from project.presenter.presenter2 import Presenter2
...

I know that i probably should put a lot of these classes into the same module, but i like the structure and short file lengths this Java-like approach gives me.

How do i handle this kind of situation without cluttering my module with 20+ lines of imports? Do i put all the imports into a separate module and import that, or is there a hack that does something like:

from project.model.* import *

Edit: Since this was marked as a duplicate, I don't want to import all of these modules (that would be easier), but import all of the classes of these modules.

Luca Fülbier
  • 2,641
  • 1
  • 26
  • 43
  • My editor folds imports. – Peter Wood Mar 21 '16 at 10:34
  • Mine does too, just a general question since python has all of these tricks to make things look nicer overall. – Luca Fülbier Mar 21 '16 at 10:37
  • 1
    As author says in his edit, this is not a duplicate of the linked question. That one is about importing multiple modules, while this is about importing specific classes from different modules. – egpbos Mar 21 '16 at 15:16

1 Answers1

1

I know of no such hack. I would indeed bundle the classes you need into meaningful new modules. It's not clear from your example whether your modules have any overlapping class names, so I would just import all the classes you have in the application into one submodule MVP, so that you can just do from project.MVP import *.

egpbos
  • 502
  • 4
  • 15
  • That was my idea aswell. Since i only need so many different imports in my main module i will probably just create an import-only-file. Thank you! – Luca Fülbier Mar 21 '16 at 10:36