How to read lines from end of a file?
Matt Dunford
kno at jtan.com
Wed Dec 22 18:08:35 EST 1999
Stig Bjorlykke <stigb at tihlde.org> writes:
>Hi all.
>I wonder how to read lines from end of a file, like this perl code:
>open FILE, "/tmp/file";
>foreach (reverse <FILE>) { ... }
>I am using it to get the latest entries in a log file.
>--
>Stig Bjrlykke
>Linux user
why not use the reverse method in python.
f = open( "/tmp/file", 'r' );
buffer = f.readlines()
buffer.reverse()
for line in buffer:
# do what you want
--
More information about the Python-list
mailing list