I tried to restructure my project for my own Tetris. With changing it to different files and also different folders I got confused about the module imports.
This is the directory
Jstris
├── code_base
│ ├── constants.py
│ ├── functions.py
│ └── tetromino.py
│
├── game_mode
│ ├── free_play.py
│ └── sprint.py
└── run.py
The main goal is to execute the run.py file and it works as it should. Just to be clear, the whole game is working. I get to a menu and can start all my different games. But I want to understand what is happening here and can't figure it out myself.
In run.py I import e.g.: (not the original code, just for demonstration)
from code_base.constants import SCREEN_HEIGHT, SCREEN_WIDTH
from code_base.functions import draw_window
from game_mode.free_play import main_free_play
In functions.py I import the following:
from code_base.constants import PLAY_WIDTH, PLAY_HEIGHT
from code_base.tetromino import Tetromino
I need to have the syntax like above in functions.py to not get an error when executing run.py. But if I want to execute functions.py I get an error "ModuleNotFoundError: No module named 'code_base'.
Do I have to accept it because I won't ever execute functions.py or is there a way my whole projects works but still every module itself is able to work fine when executing ? Or one step further, is my way to structure the files and the importing just circuitous/ not Python convention? I'm using python 3.8