gpt4 book ai didi

python - 使用python解压大文件

转载 作者:太空宇宙 更新时间:2023-11-04 06:42:53 24 4
gpt4 key购买 nike

我正在尝试使用 python 解压缩各种大小的文件(有些大小为 4GB 或更大),但是我注意到在某些情况下,尤其是当文件非常大时,文件无法解压缩。当我打开新的结果文件时,它是空的。以下是我正在使用的代码 - 我的方法有什么问题吗?

        inF = gzip.open(localFile, 'rb')
localFile = localFile[:-3]
outF = open(localFile, 'wb')
outF.write( inF.read() )
inF.close()
outF.close()

最佳答案

在这种情况下,看起来您不需要 python 对您读入的文件进行任何处理,因此您最好只使用 subprocess.Popen:

from subprocess import Popen
Popen('gunzip %s %s' % (infilename, outfilename)).wait()

您可能需要传递 shell=True,但除此之外应该不错

关于python - 使用python解压大文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23916187/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com