Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个很大的 gzip 文件(11GB),我想用 Python 尽可能快地打印出我想要的行。我曾尝试linecache.getline()使用gzip.
linecache.getline()
gzip
linecache期望得到一个文本文件。已使用压缩的文件不是gzip文本文件。做你想做的事需要两个步骤。(1) 解压文件,得到一个文本文件。(2)在文本文件上使用。你可以在 Python 中做这两件事,但只能是一个接一个。linecache
linecache
我了解您想获得特定的行,而不必解压缩整个 zipfile。但这不是 zipfile 压缩的工作方式。压缩数据中不太可能存在与文本行概念相对应的任何内容。