I'm working on a python project that looks like this
app
├── data
│ └── my_data.csv
├── utils
│ └── reader.py
├── scripts
│ └── s0.py
├── notebooks
│ └── n0.ipynb
└── main.py
In reader.py:
def read_file():
with open('./data/my_data.csv'):
print('I can read the file !')
I test.py, main.py and n0.ipynb files:
from utils.reader import read_file
read_file()
To run s0 and main, I use the command: python -m scripts.s0
and python -m main
and it works fine.
But when I try to run the notebook, it does not. I understnd why (it looks at ./data/my_data.csv
but since it's not at root level, it does not work)
Is there a way to make file reading independent from entry point in python ?
In javascript for instance, it would be esay to do, I would use path ../data/my_data.csv
in reader file and it would work independently from the file location the function is called.