I've been "fighting" with absolute and relative paths in Python for a while and I know that there are quite a few questions on this topic, but I couldn't find an answer to my particular problem.
Given the following project structure:
package/
subpackage1/
moduleX.py
moduleY.py
subpackage2/
moduleZ.py
folder1/
file1.txt
I am importing in moduleX.py
a function from moduleZ.py
which requires information stored in file1.txt
to work. I have no problem importing the function from moduleZ.py
, however since it requires file1.txt
I get the error message "No such file or directory".
My question is: When the function from moduleZ.py
tries to open file1.txt
after being imported which path does it consider?
I would like for it to work with a relative path, but I couldn't find a way for it to work.
Thanks in advance.