stdin / stdout doubts..

Steven Taschuk staschuk at telusplanet.net
Fri May 2 11:36:09 EDT 2003


Quoth Alessio Pace:
  [...]
> 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

Yes, that's fine.

Sometimes you might prefer to use the print statement to write to
stdout.

(Of course, if the file could be big, a more incremental algorithm
than the one you have above might be better, to reduce memory
usage.)

-- 
Steven Taschuk                staschuk at telusplanet.net
"I tried to be pleasant and accommodating, but my head
 began to hurt from his banality."   -- _Seven_ (1996)





More information about the Python-list mailing list