This question may be pretty elementary, but here goes:
I'm writing an app that will need lots of classes. I want to basically bundle these classes in to groups. To do that I am basically creating folders and putting the class .py files in those folders.
So an example folder structure might be this:
mainApp.py
moreAppCode.py
functions
|- mathstuff.py
|- my_object.py
`- network.py
gui
|- wxMainForm.py
|- wxSplashScreen.py
`- wxAboutBox.py
Right now, the only way I've found to easily reference these classes in "import" statements is to create __init__.py
files in the two folders and inside those init files, import each .py file. So I have to do something like:
(functions/__init__.py)
from mathstuff import mathstuff
from my_object import my_object
from network import network
This does allow me to then do something like import functions
in mainApp.py.
However, it seems to me that there should be an easier and simpler way to achieve this.
I don't really want to have to do things like import gui.wxMainForm.wxMainForm
(each .py file only contains one class represented by its filename). Also, this precludes doing anything like import gui.*
(that isn't valid). So no matter what I find I end up having to manually import every single .py file, either in the init files or in the actual .py file planning to use them.
I can mitigate some of the mess by using from gui import wxMainForm
but then I still have to do wxMainForm.wxMainForm()
. I could maybe do from gui.wxMainForm import wxMainForm
? But then we're still back to a huge mess of import statements at the top of whatever code file I'm working with.
The whole point of all this is I would like to not have to depend on that init file to get this done, because if I ever need to rename a class or add one it means a trip into init to add it or change it there - something easy to forget to do, and difficult to debug!
Have I missed something?
Thanks
-f