Re: Writing to stdout and a log file

2005-04-20 Thread Mike
Perfect. This is what I"ll use. Thanks! Mike -- http://mail.python.org/mailman/listinfo/python-list

Re: Writing to stdout and a log file

2005-04-20 Thread Michael Hoffman
Mike wrote: I should've mentioned I want StdoutLog to subclass the 'file' type because I need all the file attributes available. You might use a surrogate pattern. Here's one I use for this kind of situation, where I want to subclass but that can't be done for some reason. class SurrogateNotInite

Re: Writing to stdout and a log file

2005-04-20 Thread Mike
flushing stdout has no effect. I've got an implementation that does not subclass file. It's not as nice but it works. -- http://mail.python.org/mailman/listinfo/python-list

Re: Writing to stdout and a log file

2005-04-20 Thread Wolfram Kraus
Mike wrote: I would like my 'print' statements to send its output to the user's screen and a log file. This is my initial attempt: class StdoutLog(file): def __init__(self, stdout, name='/tmp/stdout.log', mode='w',bufsize=-1): super(StdoutLog, self).__init__(name,mode,bufsize) s

Re: Writing to stdout and a log file

2005-04-19 Thread Jeff Epler
In that case, it looks like you won't be able to get what you want without modifying CPython. PRINT_ITEM calls PyFile_SoftSpace, PyFile_WriteString, and PyFile_WriteObject, which all use PyFile_Check(). It might be as simple as changing these to PyFile_CheckExact() calls in PyFile_WriteString / P

Writing to stdout and a log file

2005-04-19 Thread Mike
I would like my 'print' statements to send its output to the user's screen and a log file. This is my initial attempt: class StdoutLog(file): def __init__(self, stdout, name='/tmp/stdout.log', mode='w',bufsize=-1): super(StdoutLog, self).__init__(name,mode,bufsize) self.stdout

Re: Writing to stdout and a log file

2005-04-19 Thread Mike
Thanks. I should've mentioned I want StdoutLog to subclass the 'file' type because I need all the file attributes available. I could add all the standard file methods and attributes to StdoutLog without subclassing 'file' but I'd rather avoid this if I can. -- http://mail.python.org/mailman/li

Re: Writing to stdout and a log file

2005-04-19 Thread Jeff Epler
This variation works: # class Tee: def __init__(self, *args): self.files = args def write(self, data): for f in self.files: result = f.write(data) return result def writelines(s