在Python 2.7中将zip文件的内容解压到特定目录
- 论坛
- 在Python 2.7中将zip文件的内容解压到特定目录
7 浏览
在Python 2.7中将zip文件的内容解压到特定目录
这是我目前正在使用的代码,用于解压缩一个与脚本位于同一当前工作目录的zip文件。我如何指定一个不同的目录来进行解压缩?
我尝试的代码没有将其解压缩到我想要的位置。
import zipfile fh = open('test.zip', 'rb') z = zipfile.ZipFile(fh) for name in z.namelist(): outfile = open('D:\\' + name, 'wb') outfile.write(z.read(name)) outfile.close() fh.close()