title: Python: How to find path to the script running a python script
body: <p>Lets say i have a python script at <code>homedir/codes/py/run.py</code>
  I also have a bash script at <code>homedir/codes/run.sh</code>
  This bash script runs <code>run.py</code> by <code>python py/run.py</code>.</p>
  
  <p>The thing is that i need to be able to find out, in <code>run.py</code>, the path to the calling script <code>run.sh</code>. If <code>run.sh</code> is run from its own directory, i can just use <code>os.getcwd()</code>. But <code>run.sh</code> can in principle be run from anywhere, and then <code>os.getcwd()</code> will return the path to where <code>run.sh</code> is run FROM, and not the actual location of <code>run.sh</code>.</p>
  
  <p>ex:</p>
  
  <ul>
  <li>At <code>homedir/codes</code>: <code>./run.sh</code> -> <code>os.getcwd()</code> returns <code>homedir/codes</code></li>
  <li>At <code>homedir</code>: <code>./codes/run.sh</code> -> <code>os.getcwd()</code> returns <code>homedir</code></li>
  </ul>
  
  <p>But i want <code>homedir/codes</code> no matter how <code>run.sh</code> is called. Is this possible?</p>