'¿How define final path when i compress with tar file library?

I'm compressing a file and his content to tar.gz with the next function.

import tarfile
import os 

def make_tarfile(output_filename, source_dir):
    with tarfile.open(f"{output_filename}.tar.gz", "w:gz") as tar:
        tar.add(source_dir, arcname=os.path.basename(source_dir))

It is working, making the "tar.gz" on the actual path of my jupyter notebook. I want to know how can I code it to introduce the final path as parameter. Thanks.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source