Reading just a few lines from a text file

tkpmep at hotmail.com tkpmep at hotmail.com
Tue Aug 23 18:07:55 EDT 2005


Right now my code reads as follows:

infile=file(FileName)
for line in reversed(infile.readlines()):  #Search from the bottom up
     if int(line.split()[0]) == MyDate:
           Data= float(line.split()[-1])
           break
infile.close()

I have to read about 10,000 files, each with data. I'm looking to speed
up each individual file open/close cycle.

Thomas Philips




More information about the Python-list mailing list