Re: reading the last line of a file

2005-09-08 Thread Michael Sparks
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

Re: reading the last line of a file

2005-09-08 Thread Xah Lee
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

Re: reading the last line of a file

2005-09-08 Thread Fredrik Lundh
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,

Re: reading the last line of a file

2005-09-08 Thread Leif K-Brooks
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

Re: reading the last line of a file

2005-09-08 Thread Fredrik Lundh
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

Re: reading the last line of a file

2005-09-08 Thread Martin Franklin
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

Re: reading the last line of a file

2005-09-08 Thread Martin Franklin
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

Re: reading the last line of a file

2005-09-08 Thread Martin Franklin
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