How do I read two lines from a file at a time using python

Similar question here. You can’t mix iteration and readline so you need to use one or the other.

while True:
    line1 = f.readline()
    line2 = f.readline()
    if not line2: break  # EOF
    ...

Leave a Comment