Redirect question

Karsten Weinert k.weinert at gmx.net
Thu Nov 21 11:48:56 EST 2002


Well, after solving my error in the Redirect class with all your help,
I now encountered a new problem. Here is the program:

import sys, win32ui

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

sys.stdout = Redirect()
sys.stderr = Redirect()
print 'Hidey Ho'
print "Hidey hidey hidey ho"
sys.stdout.flush() # is displayed
# from here, no output is produced, e.g. no messagebox
assert 1==0, "Impossible Assertion"
sys.stderr.flush() 

What am I doing wrong? Enclosing the assert statement with try/finally
or try/except only displays an empty message box.

Kind regards,
Karsten



More information about the Python-list mailing list