February 19th, 2005, 04:05 PM
Reading standard input...how to stop?
hi, I've trouble reading standard input in python. For example.if I said
for a in stdin:
bla bla bal
then, when I run my program, it keep asking me to input value...but what if I finished inputing my value? how to stop?
*I try Ctrl-C, but it end up stop the program and didn't display the results.*
February 19th, 2005, 06:40 PM
CTRL-Z on Windows
CTRL-D on Unix/Linux.
These signal 'end of file' to the OS.
Dave - The Developers' Coach
February 23rd, 2005, 02:54 AM
I'm not sure if it is normal that I have to press Ctrl-Z TWO times to stop the program...instead of one. Is that normal?
My standard input is like something:
for a in sys.stdin:
bla blab bla
February 24th, 2005, 03:43 PM
Just to alleviate any doubts about this. You should have to press Ctrl-Z once to stop reading stdin and once to exit the program if there is still work to be done, otherwise the program should get to the end and exit. You would have to press it again if for example you were inside an infinite loop.
The following program requires you to press Crtl-D once and then exits after printing what was typed.
Hope this clears everything up,
from sys import stdin
for line in stdin:
print 'STDIN:', line,
February 24th, 2005, 04:42 PM
oh i see,
yeah, my program is quite big. So the first time is only stop the stdin and the second time is stop the program and it show the results after...