一个Python包,它可以快速访问大文件中的任何行,而不会占用高内存成本。
linecache-light的Python项目详细描述
LineCache caches the line position of a file in the memory. Everytime it access a line, it will seek to the related postion and readline(). Noticing that it may cost some time when you first cache lines of a file.
Usage:
from linecache_light import LineCache
linecache = LineCache(‘a.txt’, cache_suffix=’.cache’)
num_lines = len(linecache)
line_0 = linecache[0]
line_100 = linecache[100]
line_indexing= linecache[[2,3,4,5]]
line_indexing = linecache[-1]