title: How do I get the parent directory in Python?
body: <p>Could someone tell me how to get the parent directory of a path in Python in a cross platform way. E.g.</p>
  
  <pre><code>C:\Program Files ---&gt; C:\
  </code></pre>
  
  <p>and</p>
  
  <pre><code>C:\ ---&gt; C:\
  </code></pre>
  
  <p>If the directory doesn't have a parent directory, it returns the directory itself. The question might seem simple but I couldn't dig it up through Google.</p>