Redirecting StdOut

Ugo García plugin at supercable.es
Sun Jun 23 15:25:59 EDT 2002


perfect. This is what I was looking for. Now I'd make a C module to handle
the messages written to stdout & stderr in order to show them in the screen.
Thanks a lot

--ugo
"Chris Liechti" <cliechti at gmx.net> escribió en el mensaje
news:Xns9236D1FF016AAcliechtigmxnet at 62.2.16.82...
> "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