问题描述
使用python从gz压缩的文本文件中读取一行很容易,而无需完全提取该文件吗?我有一个大约200mb的text.gz文件.当我提取它时,它变为7.4gb.这不是我必须阅读的唯一文件.对于整个过程,我必须读取10个文件.尽管这将是一项连续的工作,但我认为在不影响全部信息的情况下做到这一点将是明智之举.我什至不知道这是可能的.如何使用python完成?我需要逐行阅读文本文件.
Is it easy to read a line from a gz-compressed text file using python without extracting the file completely? I have a text.gz file which is aroud 200mb. When I extract it, it becomes 7.4gb. And this is not the only file I have to read. For the total process, I have to read 10 files. Although this will be a sequential job, I think it will a smart thing to do it without extarcting the whole information. I do not even know that it is possible. How can it be done using python? I need to read a text file line-by-line.
推荐答案
您是否尝试过使用 gzip.GzipFile ?参数类似于open
.
Have you tried using gzip.GzipFile? Arguments are similar to open
.
这篇关于python:从压缩的文本文件中读取行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!