stdin / stdout doubts..

Donn Cave donn at u.washington.edu
Fri May 2 12:28:10 EDT 2003


Quoth Alessio Pace <puccio_13 at yahoo.it>:
| Hi, I have some doubts about the way I deal with stdin and stdout.
| I do:
| import sys
|
| multi_line_text = sys.stdin.read()      
| # do something on the text
| # ...
| sys.stdout.write(modified_multi_line_text)
|
| Is this the preferable way? Or is there another way to make Python read from
| stdin/write to stdout

It's the right way as a general rule.

You could probably make the "print" statement work for output, but it
doesn't look like it would suit your application as well.  In some
exotic situations, on certain platforms (UNIX) you might have reasons
to use the posix read and write functions, for example if you have been
using select() to determine if data is available for input.

	Donn Cave, donn at u.washington.edu




More information about the Python-list mailing list