title: Python: script's directory
body: <p>I was looking for a solution, but have not found what I need.</p>
  
  <p>Script path: <em>/dir/to/script/script.py</em> or <em>C:\dir\script.py</em></p>
  
  <p>Excepted result:</p>
  
  <pre><code>$ ./script.py
  output: /dir/to/script
  $ cd .. &amp;&amp; ./script/script.py
  output: /dir/to/script
  </code></pre>
  
  <p>Is there any function in os module or something?</p>
  
  <hr>
  
  <p>I mixed solutions and write:</p>
  
  <pre><code>print os.path.abspath(os.path.dirname(__file__))
  </code></pre>
  
  <p>But it's ugly. Is there better way?</p>