import zipfile
      
      with zipfile.ZipFile(zipfile, 'w') as new_zip:
        new_zip.write('filetoadd', compress_type=zipfile.ZIP_DEFLATED)
      Python language logo

      Create new ZIP file

      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

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.