Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write a program zip.py to create a zip file. The program should take the name of

ID: 3587696 • Letter: W

Question

write a program zip.py to create a zip file. The program should take the name of zip file and files to add to the zip file. Use import zipfile.class. In python please write a program zip.py to create a zip file. The program should take the name of zip file and files to add to the zip file. Use import zipfile.class. In python please write a program zip.py to create a zip file. The program should take the name of zip file and files to add to the zip file. Use import zipfile.class. In python please

Explanation / Answer

import os
import zipfile

def zipdir(path, ziph):
    # ziph is zipfile handle
    for root, dirs, files in os.walk(path):
        for file in files:
            ziph.write(os.path.join(root, file))

if __name__ == '__main__':
    zipf = zipfile.ZipFile('Python.zip', 'w', zipfile.ZIP_DEFLATED)
    zipdir('tmp/', zipf)
    zipf.close()