index file for line numbers of large files
- file = "Desktop/coordinates.csv"
- index = [None]
- with open(file, "rt", encoding="utf8", newline=None) as fd:
- offset = 0
- for line_number, line in enumerate(fd, start=1):
- size = len(line)
- index.append((line_number, offset, size))
- offset += size + 1
- # index: line number starting with 1
- # offset, where to seek
- # size, how much to read the single line
- # first index is None, so the index fits to line numbering.
RAW Paste Data