2017-02-11 87 views

回答

0

您可以分兩步進行。首先,解壓縮.7z文件,然後將內容壓縮到zip文件。

解壓縮.7z壓縮文件

from lib7zip import Archive, formats 

with Archive('filename.7z') as archive: 
    # extract all items to the directory 
    # directory will be created if it doesn't exist 
    archive.extract('directory') 

參考:https://github.com/harvimt/pylib7zip

壓縮到壓縮文件

#!/usr/bin/env python 
import os 
import zipfile 

def zipdir(path, ziph): 
    # ziph is zipfile handle 
    for root, dirs, files in os.walk(path): 
     for file in files: 
      ziph.write(os.path.join(root, file)) 

if __name__ == '__main__': 
    zipf = zipfile.ZipFile('file.zip', 'w', zipfile.ZIP_DEFLATED) 
    zipdir('tmp/', zipf) 
    zipf.close()