如何使用Python 2.4解压缩文件? [英] How to unzip a file with Python 2.4?
本文介绍了如何使用Python 2.4解压缩文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我很难弄清楚如何使用2.4解压缩zip文件. extract()
不包含在2.4中.我只能在服务器上使用2.4.4.
I'm having a hard time figuring out how to unzip a zip file with 2.4. extract()
is not included in 2.4. I'm restricted to using 2.4.4 on my server.
有人可以提供一个简单的代码示例吗?
Can someone please provide a simple code example?
推荐答案
您必须使用namelist()
和extract()
.考虑目录的样本
You have to use namelist()
and extract()
. Sample considering directories
import zipfile
import os.path
import os
zfile = zipfile.ZipFile("test.zip")
for name in zfile.namelist():
(dirname, filename) = os.path.split(name)
print "Decompressing " + filename + " on " + dirname
if not os.path.exists(dirname):
os.makedirs(dirname)
zfile.extract(name, dirname)
这篇关于如何使用Python 2.4解压缩文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文