python code to convert an excel file into 7zip code example

Example 1: compress excel file in python

#!/usr/bin/env python3

import zipfile

zip_file = zipfile.ZipFile('file_name.zip', 'w')
zip_file.write('/tmp/hello.txt')
zip_file.close()

Example 2: looping over folder to extract zip winrar python

for root, dirs, files in os.walk(path):
    if not any(f.endswith(".mkv") for f in files):
        for file in files:
            pth = join(root, file)
            if file.endswith("zip"):
                print("Unzipping ",file, "...")
                check_call(["unzip" , pth, "-d", root])
            elif file.endswith((".rar",".r00")):
                check_call(["unrar","e", pth,  root])