Answers for "python decompress gz"

2

python Decompress gzip File

import gzip
import shutil
with gzip.open('file.txt.gz', 'rb') as f_in:
    with open('file.txt', 'wb') as f_out:
        shutil.copyfileobj(f_in, f_out)
Posted by: Guest on May-15-2020
0

python extract gz file

import tarfile

#simple function to extract the train data
#tar_file : the path to the .tar file
#path : the path where it will be extracted
def extract(tar_file, path):
    opened_tar = tarfile.open(tar_file)
     
    if tarfile.is_tarfile(tar_file):
        opened_tar.extractall(path)
    else:
        print("The tar file you entered is not a tar file")
extract('/kaggle/input/gnr-638/train.tar.xz', '/kaggle/working/gnr-638')
extract('/kaggle/input/gnr-638/test_set.tar.xz', '/kaggle/working/gnr-638')
Posted by: Guest on November-28-2020

Python Answers by Framework

Browse Popular Code Answers by Language