Unable to remove zipped file after unzipping
<p>I'm attempting to remove a zipped file after unzipping the contents on windows. The contents can be stored in a folder structure in the zip. I'm using the <code>with</code> statement and thought this would close the file-like object (<code>source</code> var) and zip file. I've removed lines of code relating to saving the source file.</p>

<pre><code>import zipfile
import os

zipped_file = r'D:\test.zip'

with zipfile.ZipFile(zipped_file) as zip_file:
    for member in zip_file.namelist():
        filename = os.path.basename(member)
        if not filename:
            continue
        source = zip_file.open(member)

os.remove(zipped_file)
</code></pre>

<p>The error returned is: </p>

<pre><code>WindowsError: [Error 32] The process cannot access the file because it is being used by another process: 'D:\\test.zip'
</code></pre>

<p>I've tried:</p>

<ul>
<li>looping over the <code>os.remove</code> line in case it's a slight timing issue</li>
<li>Using close explicitly instead of the <code>with</code> statment</li>
<li>Attempted on local C drive and mapped D Drive</li>
</ul>