Say I am making a pdf editor app with the following structure:
├── main.py
├── 📂 drawing_functions/
├── 📂 util/
├── 📂 GUI/
└── 📂 document_handling/
Each of these folders have a collection of python code, and more subfolders.
Now there are a few ways to architect this:
- Each of the folders can have an
__init__.py, and treat each folder as a module - Each of the folders can have their own
main.py, e.g.GUI/gui_main.py - Each of the folders can have their own
__main__.py - The root directory
main.pycould be__main__.py
But I am not sure how to make these architecture choices. When should you use __init__.py vs __main__.py? I know what they do, literally. __init__.py is for declaring regular packages and are immediately executed on load, __main__.py will allow you to execute from the command line with -m. But if you import GUI.gui_main then the contents will be executed just like as if you imported GUI with an __init__.py. It's also totally possible to architect a project without these. When should you be using them and when should you not?