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 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


        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.