Create new ZIP file

    0

    6

    Python public recipes

    The code first creates a new ZipFile object and stores the path to the myfile.zip file in the zipfile variable. Then, the code writes the contents of the file.txt file to the new_zip object using the zipfile.ZIP_DEFLATED compression type.

    Shortcut: zipfile.write

    import zipfile
    
    with zipfile.ZipFile(zipfile, 'w') as new_zip:
      new_zip.write('filetoadd', compress_type=zipfile.ZIP_DEFLATED)
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.