Redirect question
Robin Munn
rmunn at pobox.com
Sun Nov 17 15:11:36 EST 2002
Karsten Weinert <k.weinert at gmx.net> wrote:
> 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()
Have you tried having Redirect be a subclass of file?
>
> print 'Hidey Ho'
Does this actually call sys.stdout.write(), or some other method? It's
been too long since I experimented with this type of approach.
> 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.
Sorry I couldn't offer more help, but I hope this gives you some idea at
least of an approach to take to solving your problem.
--
Robin Munn <rmunn at pobox.com>
http://www.rmunn.com/
PGP key ID: 0x6AFB6838 50FF 2478 CFFB 081A 8338 54F7 845D ACFD 6AFB 6838
More information about the Python-list
mailing list