convert while(<>) from perl to python
i have a perl script that the basic structure of which is:
Code:
$| = 1; Code:
import sys the script needs to get a single line off the pipeline in, process it, then pipe it back out. |
Code:
while sys.stdin: Try something like this: Code:
for line in sys.stdin.readlines(): Code:
while 1: |
thanks ioerror
i've been doing a little more work on this this is run as a child process, sits and waits for input on its stdin, and returns a string Code:
read = stdin.readline I needed to flush the output buffers, maybe this is equivalent to "$| = 1" in perl. "while 1" works as well, but it won't exit gracefully when it needs to. "while line" exits in a SIGQUIT or eof. please post any recomendations, or comments. i'm just trying to figure out the efficiencies and interactions of these little programs. |
All times are GMT -5. The time now is 05:52 AM. |