I have a project folder, PythonProject
.
Within that Project folder I have a 2 subdirectories: SubDirectory
& DataSubDirectory
.
Within SubDirectory, I have a python file, TestFile.py which opens an external file, datafile.txt, contained in DataSubDirectory.
Currently, I open this file as such; open(..\\DataSubDirectory\\data.txt)
Is there a method by which I can set any file paths within my TestFile.py
to be relative to the parent project folder, so that if the file were moved to another Sub Directory, or placed in the parent directory even, I would not get a filepath error? The effect being that any file opened as such; open(data\\data.txt)
would actually be opened as open(PythonProject\\data\\data.txt)
, and not relative to whichever directory it is found?