Open this example in the interactive library
Source code
from collections import deque
from io import StringIO
last_lines = deque(StringIO('first\nsecond\nthird\n'), maxlen=2)
print(''.join(last_lines), end='')Sample output
second third

Open this example in the interactive library
from collections import deque
from io import StringIO
last_lines = deque(StringIO('first\nsecond\nthird\n'), maxlen=2)
print(''.join(last_lines), end='')second third