【发布时间】:2014-11-02 12:21:15
【问题描述】:
我有这个 zip 文件结构。
压缩文件名 = filename.zip
filename> images>
style.css
default.js
index.html
我只想更新index.html。我试图更新index.html,但它在1.zip文件中只包含index.html文件,其他文件被删除。
这是我尝试过的代码:
import zipfile
msg = 'This data did not exist in a file before being added to the ZIP file'
zf = zipfile.ZipFile('1.zip',
mode='w',
)
try:
zf.writestr('index.html', msg)
finally:
zf.close()
print zf.read('index.html')
那么如何使用 Python 仅更新 index.html 文件?
【问题讨论】:
-
到目前为止你尝试过什么?向我们展示您的代码并描述哪些功能有效,哪些无效。