Feb-23-2021, 08:17 PM
i'm reading in lines from a file by looping over the open file object so i have 1 line at a time. i need to do tests that check the last 4 lines. i need to keep a sliding window of the last 4 lines. what i have been doing is:
... buffer = bytearray() sw4 = [b'baz\n',b'bar\n',b'foo\n'] with open(fn,'rb') as f: for line in f: buffer += line sw4[:0] = line sw4[4:] = [] ...is this a good way to do that with sw4 having the last 4 lines in reverse order? are there any nice builtin tools to do this better or more clearly?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.