Just an addition to these answers.
If you want to import all files from all subdirectories, you can add this to the root of your file.
import sys, os
sys.path.extend([f'./{name}' for name in os.listdir(".") if os.path.isdir(name)])
And then you can simply import files from the subdirectories just as if these files are inside the current directory.
If I have the following directory with subdirectories in my project...
.
+-- a.py
+-- b.py
+-- c.py
+-- subdirectory_a
¦ +-- d.py
¦ +-- e.py
+-- subdirectory_b
¦ +-- f.py
+-- subdirectory_c
¦ +-- g.py
+-- subdirectory_d
+-- h.py
I can put the following code inside my a.py
file
import sys, os
sys.path.extend([f'./{name}' for name in os.listdir(".") if os.path.isdir(name)])
# And then you can import files just as if these files are inside the current directory
import b
import c
import d
import e
import f
import g
import h
In other words, this code will abstract from which directory the file is coming from.