Re: Reading just a few lines from a text file

2005-08-23 Thread John Machin
[EMAIL PROTECTED] wrote: > I have a text file with many hundreds of lines of data. The data of > interest to me, however, resides at the bottom of the file, in the last > 20 lines. Right now, I read the entire file and discard the stuff I > don't need. I'd like to speed up my program by reading onl

Re: Reading just a few lines from a text file

2005-08-23 Thread Diez B. Roggisch
[EMAIL PROTECTED] 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 reve

Re: Reading just a few lines from a text file

2005-08-23 Thread tkpmep
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 l

Re: Reading just a few lines from a text file

2005-08-23 Thread Paul McGuire
Are you sure this is really slowing down your program? "Many hundreds of lines" is not nearly enough to start Python breathing hard. I have been really impressed with just how quickly Python is able to do file input and processing, zipping through whole megs of data in just seconds. How are you

Re: Reading just a few lines from a text file

2005-08-23 Thread [EMAIL PROTECTED]
I just did strace on "tail -20 ". Apparently, it does seek to the end and reads enough data to cover 20 lines. I guess it is calculating this "size" by counting 20 new lines .You may try to do the same thing. Thanks, Raghu. -- http://mail.python.org/mailman/listinfo/python-list

Re: Reading just a few lines from a text file

2005-08-23 Thread rafi
[EMAIL PROTECTED] wrote: > I have a text file with many hundreds of lines of data. The data of > interest to me, however, resides at the bottom of the file, in the last > 20 lines. Right now, I read the entire file and discard the stuff I > don't need. I'd like to speed up my program by reading onl

Reading just a few lines from a text file

2005-08-23 Thread tkpmep
I have a text file with many hundreds of lines of data. The data of interest to me, however, resides at the bottom of the file, in the last 20 lines. Right now, I read the entire file and discard the stuff I don't need. I'd like to speed up my program by reading only the last 20 lines. How do I do