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)