我想要了解什么是最有效(速度和性能)的方式来向后读取gzip文件,而无需将整个文件的内容加载到内存中。反向读取gzip文件
这是我目前做的,但效率不高的真正的大文件:
file = 'huge_file.log.gz'
import gzip
if file.endswith('gz'):
f = gzip.open(file)
# reverse the file contents
reverse_file_list = reversed(f.read().decode('utf-8').split('\n'))
我看到有在计算器和codestate一些解决方案,这样做的负面寻求反而不利寻求在文件中不支持以二进制方式打开与gzip.open
链接: Most efficient way to search the last x lines of a file in python
http://code.activestate.com/recipes/439045/
所以解决方案失败了,我想完成。
+1使用'TAC ' –