DeaD_EyE

index file for line numbers of large files

Sep 29th, 2020
892
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. file = "Desktop/coordinates.csv"
  3.  
  4. index = [None]
  5. with open(file, "rt", encoding="utf8", newline=None) as fd:
  6.     offset = 0
  7.     for line_number, line in enumerate(fd, start=1):
  8.         size = len(line)
  9.         index.append((line_number, offset, size))
  10.         offset += size + 1
  11.  
  12.  
  13. # index: line number starting with 1
  14. #        offset, where to seek
  15. #        size, how much to read the single line
  16. # first index is None, so the index fits to line numbering.
RAW Paste Data