Something like this?
As you probably know, slice will not raise any error if indices are out-of-bounds. So you can't be sure of number of lines (if any) printed/returned:
import time with open('one_row_at_time.csv', 'r') as f: for i, line in enumerate(f, start=1): if i in range(5, 15): # rows 5-14 print(line) # use line.rstrip() to handle newline if needed time.sleep(2)One should break out of loop if needed lines are processed, but it should be trivial to add/refactor code. There is also itertools module with suitable functions.
As you probably know, slice will not raise any error if indices are out-of-bounds. So you can't be sure of number of lines (if any) printed/returned:
>>> 'abc'[2:20] 'c' >>> 'abc'[5:20] ''
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.