I’m building a project and I have run into the following problem:
I have implemented several subclasses, each of them having about 250 lines of code. Semantically, they should go together in the same module and I want to import them with
from mymodule import SubclassA, SubclassB
But then my module file has thousands of lines, which makes maintaining its code pretty nasty. Now I have each class in a separate file to make it easier to maintain but I have to use it like this:
from subclassa import SubclassA
from subclassb import SubclassB
this does not make any sense and it’s really awful.
Is there any elegant solution? If not, which of the aforementioned is the better solution?
You can always put the
from subclassa ...imports into your package’s__init__.pyas you showed in your second listing. Then, they will be available directly off of your package as you wrote in your first listing.