Look at these 3 files and imagine they're stored in different folders:
#file1 in top_folder
from sub_folder.file2 import two
#file2 in top_folder/sub_folder
from file3 import three
two = 2
#file3 in top_folder/sub_folder
three = 3
Running file 2 directly doesn't throw an error.
Running file1 throws an error in file2 on the line from file3 import three
. file2 can't find file3 and I think this is because the relative path is relative to file1 - not file2!
I found a workaround - to use absolute paths like so:
#file2
exec(open("{path_to_file3").read())
But I'm convinced this isn't the best practice for overcoming the issue I'm describing. Are there other ways?