我很难弄清楚如何使用2.4解压缩zip文件。 extract()不包含在2.4中。我只能在服务器上使用2.4.4。

有人可以提供一个简单的代码示例吗?

最佳答案

您必须使用namelist()extract()。考虑目录的样本

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)

10-07 12:18
查看更多