Find directory of a file in Python
<p>If I have the following file:</p>

<pre><code>file = '/Users/david542/Desktop/work.txt'
</code></pre>

<p>I can use <code>os.path.basename(file)</code> to get the file name.</p>

<p>What command would I use to get the directory of the file (i.e., to get "/Users/david542/Desktop") ?</p>
