Faster alternative to Python's zipfile module?

前端 未结 1 1433
悲&欢浪女
悲&欢浪女 2021-02-13 09:48

Is there a noticeably faster alternative to Python 2.7.4 zipfile module (with ZIP_DEFLATED) for zipping a large number of files into a single zip file? I had a look at czipfile

相关标签:
1条回答
  • 2021-02-13 10:14

    As Patashu mentions, outsourcing to 7-zip might be the best idea.

    Here's some sample code to get you started:

    import os
    import subprocess
    
    path_7zip = r"C:\Program Files\7-Zip\7z.exe"
    path_working = r"C:\temp"
    outfile_name = "compressed.zip"
    os.chdir(path_working)
    
    ret = subprocess.check_output([path_7zip, "a", "-tzip", outfile_name, "*.txt", "*.py", "-pSECRET"])
    

    As martineau mentioned you might experiment with compression methods. This page gives some examples on how to change the command line parameters.

    0 讨论(0)
提交回复
热议问题