0

我使用的是 Python 2.5,无法升级 python 版本。
以下是我正在做的事情。

call(['cp', zipFileName, zipPath]) os.chdir(zipPath) call(['unzip', zipFileName])

在上面的代码中,我遇到了错误。
解压缩:找不到或打开 gunzip gunzip.zip 或 gunzip.ZIP

我确实尝试了下面的代码。但仍然得到同样的错误。

for each in zip.namelist(): if not each.endswith('/'): root, name = split(each) directory = norm(join(path, root)) if not isdir(directory): os.makedirs(directory) file(join(directory, name), 'wb').write(zip.read(each))

如果您知道任何解决方法,请提出解决方法。
谢谢。

4

1 回答 1

0

使用zipfile模块?

import zipfile

zf = zipfile.ZipFile(zipFileName)
zf.extractall(path=zipPath)
zf.close()

这会将 zip 文件中的所有文件提取到目录“zipPath”中。

因为您的 Python 版本小于 2.7.4,请阅读关于extract()https://docs.python.org/2/library/zipfile.html#zipfile.ZipFile.extractallextractall()警告。

于 2014-07-31T12:43:21.103 回答