[Tutor] reassigning/replacing sys.stdout

Tony Cappellini cappy2112 at gmail.com
Tue Jan 30 09:22:13 CET 2007


I'm writing a python gui app that will call a python cmd line app. The gui
will take users input, pass it to the cmd line app, then display the cmd app
program output. The idea is to give users who aren't comfortable with the
cmd line a way to run the program, without having to open a shell window (on
Linux) or cmd prompt  (On Windows) and get hung up on syntax or shell
issues. It's a crutch.

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'.
The author is now out of communications for a few weeks,  so I can't
elaborate.

However, I've opened a file which writes to the disk, and replaced that
sys.stdout with that file descriptor.
I can then close and open that file and have the output of his program.
Now I can just put this in a textbox on the gui and display it to the user.

Writing to a file on disk, then reading it back in seems a bit clunky to me.
While I did somewhat do what the author had suggested (although I didn't
make a class out of the file descriptor), and it works, is there a better
way?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070130/89f38a10/attachment.htm 


More information about the Tutor mailing list