I just came across this piece of code
while 1: line = data.readline() if not line: break #...
and thought, there must
If data has a function that returns an iterator instead of readline (say data.iterate), you could simply do:
data
readline
data.iterate
for line in data.iterate(): #...