How to read lines only at the end of file?
Christopher Koppler
klapotec at chello.at
Fri Nov 7 03:55:25 EST 2003
On Fri, 07 Nov 2003 08:32:22 +0900, Kay Lee <aeronova at bs21.net> wrote:
>Hi,
>I need to know how to make small scripts that acts like 'tail' command
>in unix with python.
>Any advice will be very helpful to me.
>Thanks in adv.
You could do the following:
>>> f = file('filename.txt', 'r')
>>> numberoflines = 10
>>> for line in f.readlines()[-numberoflines:]:
... print line
which prints the last 10 lines of the file.
--
Christopher
More information about the Python-list
mailing list