Reading just a few lines from a text file

Diez B. Roggisch deets at nospam.web.de
Tue Aug 23 18:51:10 EDT 2005


tkpmep at hotmail.com wrote:
> Right now my code reads as follows:
> 
> infile=file(FileName)
> for line in reversed(infile.readlines()):  #Search from the bottom up

Not sure if python does some tricks here - but for me that seems to be 
uneccesary shuffling around of data. Better do

for line in reversed(infile.readlines()[:-10]):
     ...


Diez



More information about the Python-list mailing list