Lookahead while doing: for line in fh.readlines():

Veek. M vek.m1234 at gmail.com
Sat Feb 27 04:39:56 EST 2016


I want to do something like:

#!/usr/bin/env python3

fh = open('/etc/motd')
for line in fh.readlines():
    print(fh.tell())

why doesn't this work as expected.. fh.readlines() should return a 
generator object and fh.tell() ought to start at 0 first.

Instead i get the final count repeated for the number of lines.

What i'm trying to do is lookahead:
#!whatever

fh = open(whatever)
for line in fh.readlines():
    x = fh.tell()
    temp = fh.readline()
    fh.seek(x)



More information about the Python-list mailing list