title: How can I find script's directory?
body: <p>Consider the following Python code:</p>
  
  <pre><code>import os
  print os.getcwd()
  </code></pre>
  
  <p>I use <code>os.getcwd()</code> to <a href="http://www.faqs.org/docs/diveintopython/regression_path.html" rel="noreferrer">get the script file's directory location</a>. When I run the script from the command line it gives me the correct path whereas when I run it from a script run by code in a Django view it prints <code>/</code>.</p>
  
  <p>How can I get the path to the script from within a script run by a Django view?</p>
  
  <p><strong>UPDATE:</strong><br>
  Summing up the answers thus far - <code>os.getcwd()</code> and <code>os.path.abspath()</code> both give the current working directory which may or may not be the directory where the script resides. In my web host setup <code><code>__file__</code></code> gives only the filename without the path.</p>
  
  <p>Isn't there any way in Python to (always) be able to receive the path in which the script resides?</p>