End of file

duikboot adijkstra at baanders NOSPAM consultancy.nl
Thu Oct 7 03:46:47 EDT 2004


Kat wrote:
> Hi ,
> How do you identify the last line of a file? I am in a "for" loop and
> need to know which is the last line of the file while it is being read
> in this loop.
> 
> Thanks
> Kat

f = open("test.txt").readlines()
lines = len(f)
print lines
counter = 1
for line in f:
     if counter == lines:
         print "last line: %s" % line
     counter += 1

-- 
http://www.baandersconsultancy.nl | http://www.nosonis.com



More information about the Python-list mailing list