What is the difference between 'with open(...)' and 'with closing(open(...))'
<p>From my understanding,</p>

<pre><code>with open(...) as x:
</code></pre>

<p>is supposed to close the file once the <code>with</code> statement completed. However, now I see</p>

<pre><code>with closing(open(...)) as x:
</code></pre>

<p>in one place, looked around and figured out, that <code>closing</code> is supposed to close the file upon finish of the <code>with</code> statement.</p>

<p>So, what's the difference between closing the file and <code>closing</code> the file?</p>

<p>Assuming that's <code>contextlib.closing</code> and the standard, built-in <code>open</code>, <code>closing</code> is redundant here. It's a wrapper to allow you to use <code>with</code> statements with objects that have a <code>close</code> method, but don't support use as context managers. Since the file objects returned by <code>open</code> are context managers, <code>closing</code> is unneeded.</p>

python