Say I have a python script in homedir/codes/py/run.py
I also have a bash script at homedir/codes/run.sh
This bash script works run.pyon python py/run.py.
The thing is, I need to find out the run.pypath to the calling script run.sh. If run.shlaunched from its own directory, I can just use os.getcwd(). But run.shyou can, in principle, run from anywhere, and then os.getcwd()return the path to where run.shFROM is running, and not the actual location run.sh.
Example:
- Q
homedir/codes: ./run.sh→ os.getcwd()returnshomedir/codes - Q
homedir: ./codes/run.sh→ os.getcwd()returnshomedir
But I want homedir/codesno matter how called run.sh. Is it possible?
source
share