Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A simple file wrapper to allow seeking to specific lines at random.
class LineSeekableFile:
def __init__(self, seekable):
self.fin = seekable
self.line_map = list() # Map from line index -> file position.
while seekable.readline():
def __getitem__(self, index):
# NOTE: This assumes that you're not reading the file sequentially. For that, just use 'for line in file'.[index])
return self.fin.readline()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.