title: Is a python script aware of its stored location path?
body: <pre><code>/home/bar/foo/test.py:
  </code></pre>
  
  <p>I am trying <code>test.py</code> to print <code>/home/bar/foo</code> irrespective of from where I run the script from:</p>
  
  <pre><code>import os
  def foo():
    print os.getcwd()
  </code></pre>
  
  <p>test run:</p>
  
  <pre><code>[/home/bar $] python /home/bar/foo/test.py        # echoes /home/bar
  [/tmp $] python /home/bar/foo/test.py             # echoes /tmp
  </code></pre>
  
  <p><code>os.getcwd()</code> not the function for the task. How can I get this done otherwise?</p>