[Tutor] keeping track of the present line in a file

Kent Johnson kent37 at tds.net
Thu Jan 21 13:42:39 CET 2010


On Thu, Jan 21, 2010 at 1:57 AM, sudhir prasad <sudheer.kay at gmail.com> wrote:
> hi,
> is there any other way to keep track of line number in a file other than
> fileinput.filelineno()

With enumerate():

for line_number, line in enumerate(open('myfile.txt')):
  # etc

Kent


More information about the Tutor mailing list