无法从python脚本解压缩文件

阿吉特

我正在使用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))

如果您知道的话,请提出解决方法。
谢谢。

姆霍克

使用zipfile模块?

import zipfile

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

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

由于您的Python版本<2.7.4,请阅读有关extract()的警告extractall()网址https://docs.python.org/2/library/zipfile.html#zipfile.ZipFile.extractall

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章