Open file and with statement in Python
<p>I have a function like:</p>

<pre><code>def func(filename):
    with open(filename) as f:
        return [line.split('\t')[0] for line in f]
</code></pre>

<p>Is the "with" statement closing the file even when there is a 'sudden' function return? Can I ignore the "with" statement? i.e. is it safe and equivalent (from a memory leak perspective) to do,</p>

<pre><code>def func(filename):
    return [line.split('\t')[0] for line in open(filename)]
</code></pre>

<p>?</p>
