how to access previous line while we are accessing lines one by one in a loop using python?
<p>this is my code to print 20 lines at a time but I want to print 20 lines and then i want to start printing from 20th line how can I do that can anyone tell me? please</p>

<pre><code>f1=open("sample.txt","r")
last_pos=0
line=0
while True:
    for i,l in enumerate(f1):
        #l=f1.readline()
        if l=="":
            break
        line+=1
        print l
        if line == 20:
            last_pos=f1.tell()
            print(last_pos)
            break
f1.close()
</code></pre>

<p>To locate some line, you can use seek() function.</p>

python file