I have a python project where I have numerous classes in a structure that can be simplified to
Root of project
|------main.py
|
|------folder1
| |-------class1.py
| |
| |-------SubFolder1
| |
| |--------subClass1.py
| |--------config1.json
| |--------config2.json
... ...
subClass1 has to read and even modify numerous json files.
I am using paths relative to the folder where the I/O is done, i.e. subFolder1 which contains subClass1. However, for some reason, the path has to be changed depending on where I execute the initial code.
If I run "__main__" == __name__:
in subClass1.py to execute the methods I want, there is no issue, but when testing from class1.py, I have to go back to the paths and modify them.
Is there a way around this without writing absolute paths, as I may rearrange the directory structure, and it would be nice if I wouldn't have to mess around with changing the paths.