howto redirect stdout/stderr into a wxPython textctrl?

POYEN OP Olivier (DCL) Olivier.POYEN at clf-dexia.com
Tue Jul 29 11:28:23 CEST 2003



> -----Message d'origine-----
> De : newgene [mailto:newgene at bigfoot.com]
> Envoyé : lundi 28 juillet 2003 18:53
> À : python-list at python.org
> Objet : howto redirect stdout/stderr into a wxPython textctrl?
> 
> 
> Hi, group,
>     I guess it is a simple question for you, but it puzzles me for a
> while.
>     I use a wxTextCtrl in my application for output result and any
> exception msg. I know I can add new msg onto wxTextCtrl by WriteText()
> method. But I have a function imported from another module and in this
> function all results are output by "print". I am wondering if I can
> redirect stdout and stderr into the wxTextCtrl object, so that all
> output from that function will be shown up on wxTextCtrl box and I
> don't need modify the current code for that function.
> 
> Thank you.
> 
> 
> Chunlei
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 


class myOutForWxText:
    def __init__(self,aWxTextCtrl):
		self.out=aWxTextCtrl

    def write(self,string):
		self.out.WriteText(string)


myout=myOutForWxText(myWxTextInstance)
import sys
sys.stdout=myout

Then, when you want to recover the real stdout
sys.sdtout=sys.__stdout__

Beware: since the sys module is imported once, all the print statemens will commit to this 'myout' things.

The point is to create an object which has a write method, and assign sys.stdout to it.


HTH,

---OPQ
-------------- next part --------------
-----------------------------------------------------------------

Ce message est confidentiel ; son contenu ne represente en aucun

cas un engagement de la part de Dexia Credit Local ou de Dexia

CLF Banque. Toute publication, utilisation ou diffusion, meme

partielle, doit etre autorisee prealablement par l'emetteur. Si

vous n'etes pas destinataire de ce message, merci d'en avertir

immediatement l'expediteur.



This message is confidential ; its contents do not constitute a

commitment by Dexia Credit Local or Dexia CLF Banque. Any

unauthorised disclosure, use or dissemination, either whole or

partial, is prohibited. If you are not the intended recipient of

the message, please notify the sender immediately.

-----------------------------------------------------------------

Consultez notre site internet www.dexia-clf.fr

La cle d'une gestion optimisee du secteur public local

-----------------------------------------------------------------


More information about the Python-list mailing list