Redirect question

Karsten Weinert k.weinert at gmx.net
Sun Nov 17 10:45:05 EST 2002


Hi,
I have a question about redirecting. Here is a small program I found
on the web which I slightly modified; but now it does not run:

import win32ui, sys

class Redirect:
  def __init__(self):
    self.s=""
  def write(self, s):
    self.s+=s
  def flush(self):
    win32ui.MessageBox(s)

sys.stdout = sys.stderr = Redirect()

print 'Hidey Ho'
sys.stdout.flush()

I was expecting that when I call .flush() the MessageBox pops up. But
nothing happens (Python 2.2 on Win98, the program passed to python.exe
with a file).

I am looking for such a "delayed" Output because many error messages
are multi-line, so redirecting brings up several messageboxes for each
error. So I would like to do

try:
  assert 1==0
finally:
  sys.stderr.flush()

to get one messagebox only.
Can you advise me how I can fix above program or get the wanted
feature on an other way?

Kind regards,
Karsten.



More information about the Python-list mailing list