Redirecting StdOut

Chris Liechti cliechti at gmx.net
Sun Jun 23 14:36:02 EDT 2002


"Ugo García" <plugin at supercable.es> wrote in
news:1024856420.145085 at seux119: 

> Hi all. I'm making a game and I'm using Python as the script language.
> I'm including a console to communicate with Python. I can
> interactively send commands to the interpreter but I can't obtain the
> response from it. Is there any way to redirect stdout and stderr in
> order to print its contain to the screen?

sure. just assign a file like object to sys.stderr and stdout.

class DummyFileForWrites:
    	def write(self, text):
    	    	#write 'text' to GUI here

sys.stdout = sys.stderr = DummyFileForWrites()

so you can do the same for sys.stdin but then you would need read, 
readline, and readlines.

chris

-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list