So, I have a following file structure:
main.py
├── net
└── src
├── file.py
└── dataset
└── image.jpg
I use import net.src.file
to import file.py
into main.py
, that part works.
A function in file.py
needs the image.jpg
. However, for some reason, it can't utilize relative path, i. e. open("dataset/img.jpg")
, it needs the full path, as if we were going from main.py
- open("net/src/dataset/image.jpg")
.
Can I import a file and use its functions and force those functions to get a path from their respective directory? (Not root
but src
)
I don't want to just give it the path from main.py
, because I would have to redo a lot of functions, the code is basically a combination of two codebases (It tries to use file.py
as a library).
Functions work fine when executing file.py
standalone, but when imported from main.py
it gives the error - FileNotFoundError: [Errno 2] No such file or directory: open("dataset/img.jpg")
.