Xah Lee wrote:
> isn't there a way to implement tail in python with the same class of
> performance?
>
> how's tail implemented?:
Those crazy open source developers have an implementation here:
http://cvs.sourceforge.net/viewcvs.py/mkcdrec/mkcdrec/busybox-0.60.5/Attic/tail.c?rev=1.1&view=markup
I
isn't there a way to implement tail in python with the same class of
performance?
how's tail implemented?
Xah
[EMAIL PROTECTED]
∑ http://xahlee.org/
Fredrik Lundh wrote:
> Fredrik Lundh wrote:
>
> > zcat|tail is a LOT faster.
>
> and here's the "right way" to use that:
>
> from subprocess
Fredrik Lundh wrote:
> zcat|tail is a LOT faster.
and here's the "right way" to use that:
from subprocess import Popen, PIPE
p1 = Popen(["zcat", filename], stdout=PIPE)
p2 = Popen(["tail", "-1"], stdin=p1.stdout, stdout=PIPE)
last_line = p2.communicate()[0]
(on my small sample,
Xah Lee wrote:
> i switched to system call with tail because originally i was using a
> pure Python solution
>
> inF = gzip.GzipFile(ff, 'rb');
> s=inF.readlines()
> inF.close()
> last_line=s[-1]
>
> and since the log file is 100 megabytes it takes a long time
Martin Franklin wrote:
> Ok, in that case stick to your shell based solution, although 100
> megabytes does not sound that large to me I guess it is relative
> to the system you are running on :) (I have over a gig of memory here)
since the file is gzipped, you need to read all of it to get the l
Martin Franklin wrote:
> Martin Franklin wrote:
>
>>Xah Lee wrote:
>>
>>
>>>Martin Franklin wrote:
>>>
>>>
>>>
import gzip
log_file = gzip.open("access_log.4.gz")
last_line = log_file.readlines()[-1]
log_file.close()
>>>
>>>
>>>does the
>>>log_file.readlines()[-1]
>>>actually read
Martin Franklin wrote:
> Xah Lee wrote:
>
>>Martin Franklin wrote:
>>
>>
>>>import gzip
>>>log_file = gzip.open("access_log.4.gz")
>>>last_line = log_file.readlines()[-1]
>>>log_file.close()
>>
>>
>>does the
>>log_file.readlines()[-1]
>>actually read all the lines first?
>
>
>
> Yes I'm afraid
Xah Lee wrote:
> Martin Franklin wrote:
>
>>import gzip
>>log_file = gzip.open("access_log.4.gz")
>>last_line = log_file.readlines()[-1]
>>log_file.close()
>
>
> does the
> log_file.readlines()[-1]
> actually read all the lines first?
Yes I'm afraid it does.
>
> i switched to system call wi