[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:

  f = open('foo.txt')
  for line in f:
     print line

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 
In that case you need to figure out how to stop the loop - maybe 
is good enough.


Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list