[Tutor] reassigning/replacing sys.stdout

Alan Gauld alan.gauld at btinternet.com
Tue Jan 30 11:29:28 CET 2007

"Tony Cappellini" <cappy2112 at gmail.com> wrote

> The author of the cmd line app suggested I temporarily replace
> sys.stdout'with a file descriptor class that can write directly to 
> the
> gui'.

I'm not sure that would be such a great idea since the
command line tool knows nothing about the GUI - size,
height, fonts etc.

A more common approach would be to use popen() to capture
the output as a string and then the GUI can format it
appropriately for display. popen effectively captures stdout
(and stderr if needed).

Of course to be totally 'correct' you should use the new
subprocess module to do the same thing...

I suspect that is both easier and would give a better
quality result to your users.

Alan G. 

More information about the Tutor mailing list