reading the last line of a file
Xah Lee
xah at xahlee.org
Thu Sep 8 17:54:20 EDT 2005
isn't there a way to implement tail in python with the same class of
performance?
how's tail implemented?
Xah
xah at xahlee.org
∑ 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 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, this is roughly 15 times faster than the empty for loop)
>
> </F>
More information about the Python-list
mailing list