I have a python script that loads data files using relative paths. I then have a shell script from a parent directory that runs the python script like so
automate.sh contents:
python3 /path/to/python/file/file.py
file.py contents:
import numpy as np
np.loadtxt(./data/data2load.txt)
The problem is when I run this python script from the shell script, the relative path is broken. It tries to find the file to load in /path/to/shell/script/data/data2load.txt.
Is there a robust way to fix this without using absolute paths?
The fix I currently have is in my automate.sh, I instead write:
cd /path/to/python/file
python3 file.py
cd ../../../..
But this is obviuosly really tedious