Appending a log file and see progress as program executes
Matteo
mahall at ncsa.uiuc.edu
Wed May 30 14:33:42 EDT 2007
On May 30, 1:29 pm, Matteo <mah... at ncsa.uiuc.edu> wrote:
> - Write an autoflush class:
> class AutoFlush:
> def __init__(self, stream):
> self.stream = stream
> def write(self, text):
> self.stream.write(text)
> self.stream.flush()
>
> ...
> flog=open('out.log','a')
> flog=AutoFlush(flog)
>
> print >>flog,"I'm a message!"
Oops! According to another thread, this won't work for files (but will
work for stdio/stderr)
Check the thread entitled "print bypasses calling write method for
objects inheriting from file?"
More information about the Python-list
mailing list