Here is the folder structure of my code:
project/
latplan/
__init__.py
model.py
samples/
text.txt
main2.py
lyrics/
main.py
Content of each file:
main.py
#!/usr/bin/env python
import sys
sys.path.append(r"../project")
import latplan
... = some other code where latplan module was needed, then:
latplan.model.NN().load()
main2.py
#!/usr/bin/env python
import latplan
latplan.model.NN().load()
model.py
class NN():
x = 5
def load(self):
with open("samples/text.txt", "r") as f:
print("success")
When I execute main2.py (from project/ folder):
./main2.py
I get :
success
But when I execute main.py (from lyrics/ folder):
./main.py
I get the error:
"\lyrics../project\latplan\model.py", line 6, in load with open("samples/text.txt", "r") as f: FileNotFoundError: [Errno 2] No such file or directory: 'samples/text.txt
I can only modify main.py file, so how can I do so, in order to avoid this error ?
Thanks a lot