我很难弄清楚如何使用2.4解压缩zip文件。extract()不包含在2.4中。我只能在服务器上使用2.4.4。
extract()
有人可以提供一个简单的代码示例吗?
您必须使用namelist()和extract()。考虑目录的样本
namelist()
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)