How to unzip a file with Python 2.4?

后端 未结 5 713
旧巷少年郎
旧巷少年郎 2020-12-08 09:42

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.

Ca

5条回答
  •  情歌与酒
    2020-12-08 10:30

    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)
    

提交回复
热议问题