1import gzip
2f_in = open('/home/joe/file.txt')
3f_out = gzip.open('/home/joe/file.txt.gz', 'wb')
4f_out.writelines(f_in)
5f_out.close()
6f_in.close()
1import gzip
2import shutil
3with gzip.open('file.txt.gz', 'rb') as f_in:
4 with open('file.txt', 'wb') as f_out:
5 shutil.copyfileobj(f_in, f_out)
1import tarfile
2
3#simple function to extract the train data
4#tar_file : the path to the .tar file
5#path : the path where it will be extracted
6def extract(tar_file, path):
7 opened_tar = tarfile.open(tar_file)
8
9 if tarfile.is_tarfile(tar_file):
10 opened_tar.extractall(path)
11 else:
12 print("The tar file you entered is not a tar file")
13extract('/kaggle/input/gnr-638/train.tar.xz', '/kaggle/working/gnr-638')
14extract('/kaggle/input/gnr-638/test_set.tar.xz', '/kaggle/working/gnr-638')