deque to read the last line of files as follows.
from pathlib import Path from collections import deque fn = Path('myfile.txt') with fn.open('r') as f: last = deque(f,1)
- last line of file. Throws
IndexErrorif file is empty.
1 the last N lines of the file may be read and indexed.