[Tutor] parsing a continuous log file
Alan Gauld
alan.gauld at btinternet.com
Fri Nov 30 01:06:09 CET 2007
"ray sa" <bizag007 at yahoo.com> wrote
> used in UNIX called the tail command.
>
> May be someone can help me to achieve the same result with modifying
> the above code?
Sorry i didnm't look too closely but i think you should only need to
keep the file open andd then loop around with a delay.
Sometjing like:
try:
f = open('foo.txt')
for line in f:
print line
time.sleep(1)
finally:
f.close()
That will keep reading the lines until it hits the end of the file.
Of course if the file is eventually empty then it exits so you
may want a while True loop instead and only print if the line is non
empty
In that case you need to figure out how to stop the loop - maybe
Ctrl-C
is good enough.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list