def compress_directory(directory, filename):
 mode = 'w:gz'
 name = path(directory).name
 with tarfile.open(filename, mode) as tar_file:
  tar_file.add(directory, arcname=name)

def compress_directory ( directory , filename ) : mode = 'w:gz' name = path ( directory ) . name with tarfile . open ( filename , mode ) as tar_file : tar_file . add ( directory , arcname = name )
compress a directory into a tar .