擅长:python、mysql、java
<p>要启用压缩,请在构造函数中指定压缩方法:</p>
<pre><code>zip = zipfile.ZipFile(loczip, "w", zipfile.ZIP_DEFLATED)
</code></pre>
<p>我想你是在请求删除zip文件中文件的相对路径。如果你真的想要,你可以写:</p>
<pre><code>zip.write(locfile, os.path.basename(locfile))
</code></pre>
<p>但是,这可能是一个坏主意,因为删除所有路径信息将导致命名冲突,如果您压缩两个同名文件。</p>