Re: efficient 'tail' implementation

2005-12-15 Thread Marius Gedminas
Magnus Lycka wrote: To read the last x bytes of a file, you could do: import os x = 2000 # or whatever... f=open('my_big_file') l=os.fstat(f.fileno()).st_size f.seek(l-x) f.read() You don't need fstat/st_size, you can ask seek to move to an offset relative to the end of the

Re: efficient 'tail' implementation

2005-12-09 Thread Bengt Richter
On Thu, 08 Dec 2005 02:09:58 -0500, Mike Meyer [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] writes: I have a file which is very large eg over 200Mb , and i am going to use python to code a tail command to get the last few lines of the file. What is a good algorithm for this type of task in

Re: efficient 'tail' implementation

2005-12-09 Thread Magnus Lycka
[EMAIL PROTECTED] wrote: hi I have a file which is very large eg over 200Mb , and i am going to use python to code a tail command to get the last few lines of the file. What is a good algorithm for this type of task in python for very big files? Initially, i thought of reading everything

Re: efficient 'tail' implementation

2005-12-09 Thread Colin J. Williams
[EMAIL PROTECTED] wrote: hi I have a file which is very large eg over 200Mb , and i am going to use python to code a tail command to get the last few lines of the file. What is a good algorithm for this type of task in python for very big files? Initially, i thought of reading everything

Re: efficient 'tail' implementation

2005-12-08 Thread Gerald Klix
As long as memory mapped files are available, the fastest method is to map the whole file into memory and use the mappings rfind method to search for an end of line. The following code snippets may be usefull: reportFile = open( filename ) length = os.fstat( reportFile.fileno()

Re: efficient 'tail' implementation

2005-12-08 Thread Jerry Sievers
[EMAIL PROTECTED] writes: hi I have a file which is very large eg over 200Mb , and i am going to use python to code a tail command to get the last few lines of the file. What is a good algorithm for this type of task in python for very big files? Initially, i thought of reading everything

Re: efficient 'tail' implementation

2005-12-08 Thread Nick Craig-Wood
Gerald Klix [EMAIL PROTECTED] wrote: As long as memory mapped files are available, the fastest method is to map the whole file into memory and use the mappings rfind method to search for an end of line. Excellent idea. It'll blow up for large 2GB files on a 32bit OS though. -- Nick

Re: efficient 'tail' implementation

2005-12-08 Thread Nick Craig-Wood
Gerald Klix [EMAIL PROTECTED] wrote: As long as memory mapped files are available, the fastest method is to map the whole file into memory and use the mappings rfind method to search for an end of line. Actually mmap doesn't appear to have an rfind method :-( Here is a tested solution

Re: efficient 'tail' implementation

2005-12-08 Thread Neal Becker
[EMAIL PROTECTED] wrote: hi I have a file which is very large eg over 200Mb , and i am going to use python to code a tail command to get the last few lines of the file. What is a good algorithm for this type of task in python for very big files? Initially, i thought of reading everything

efficient 'tail' implementation

2005-12-07 Thread s99999999s2003
hi I have a file which is very large eg over 200Mb , and i am going to use python to code a tail command to get the last few lines of the file. What is a good algorithm for this type of task in python for very big files? Initially, i thought of reading everything into an array from the file and

Re: efficient 'tail' implementation

2005-12-07 Thread bonono
[EMAIL PROTECTED] wrote: hi I have a file which is very large eg over 200Mb , and i am going to use python to code a tail command to get the last few lines of the file. What is a good algorithm for this type of task in python for very big files? Initially, i thought of reading everything

Re: efficient 'tail' implementation

2005-12-07 Thread Mike Meyer
[EMAIL PROTECTED] writes: I have a file which is very large eg over 200Mb , and i am going to use python to code a tail command to get the last few lines of the file. What is a good algorithm for this type of task in python for very big files? Initially, i thought of reading everything into

Re: efficient 'tail' implementation

2005-12-07 Thread bonono
Mike Meyer wrote: It would probably be more efficient to read blocks backwards and paste them together, but I'm not going to get into that. That actually is a pretty good idea. just reverse the buffer and do a split, the last line becomes the first line and so on. The logic then would be no