[Tutor] input/output redirection

David Rock david at graniteweb.com
Thu Sep 8 21:18:06 CEST 2005


* Lane, Frank L <frank.l.lane at boeing.com> [2005-09-08 09:49]:
> Hi List,
>  
> I wanted to take the stdout of a process and redirect it to stdin of a
> python script, then after playing with the input in the script I want to
> send it back to stdout (all of this to be done while the original
> process runs happily along).  I can't seem to figure out the correct
> syntax if this is possible.
>  
> e.g.
>  
> C:\> runner.exe | script.py
> C:\> runner.exe > script.py  # this overwrites your script!:-)

I use fileinput for most of my stdin text processing. It also give me
the flexibility of using it as a pipe OR assigning a wordlist of files
to the script instead.

http://www.python.org/doc/2.4.1/lib/module-fileinput.html

import fileinput
for line in fileinput.input():
    process(line)


-- 
David Rock
david at graniteweb.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20050908/af60c76f/attachment.pgp


More information about the Tutor mailing list