在 python 中快速解压 .gz 文件

问题描述 投票:0回答:0

我有 300 个 .gz 文件,我必须尽快解压缩。每个文件大约 6MB,生成的未压缩文件大约 90MB。

我注意到解压缩单个文件大约需要 1 秒。我的 python 代码如下

import gzip
import shutil
import time

ts = time.time()
with gzip.open('file.csv.gz', 'rb') as f_in:
    with open('file.csv', 'wb') as f_out:
        shutil.copyfileobj(f_in, f_out)
print(time.time()-ts) #output: 1.39

由于我必须解压缩更多文件,我想找到一种方法(如果可能的话)使解压缩过程更快。有什么想法吗?

python performance unzip gunzip
© www.soinside.com 2019 - 2024. All rights reserved.