A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2005-September/304221.html below:

reading the last line of a file

reading the last line of a file reading the last line of a fileLeif K-Brooks eurleif at ecritters.biz
Thu Sep 8 07:23:13 EDT 2005
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 and hogs
> massive memory.

How about:

inF = gzip.GzipFile(ff, 'rb')
for line in inF:
    pass
last_line = line

It's a bit slower than gzip and tail, but the memory usage is fine.

More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4