简体   繁体   中英

Trying to unzip tar.gz file and save it as multiple readable text files in a folder and then recompress it

import gzip
import os
os.mkdir('uncompressed')
with gzip.open("Raw_feature_count_data.tar.gz", "rt") as f:
    output=f.read()
output

Trying to unzip multiple feature counts text files using python, the code does unzip it but i'ts unreadable and merges all the files together. Any suggestions would be appreciated.

Tarfile is the module to use. And it can handle gzip compression using the r:gz mode. From the examples at the bottom of documentation

import tarfile
tar = tarfile.open("sample.tar.gz")
tar.extractall()
tar.close()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM