Why do I have to press Ctrl+D twice to close stdin?

后端 未结 5 809
死守一世寂寞
死守一世寂寞 2021-01-04 05:12

I have the following Python script that reads numbers and outputs an error if the input is not a number.

import fileinput
import sys
for line in (txt.strip()         


        
5条回答
  •  庸人自扰
    2021-01-04 05:57

    The first time it considers it to be input, the second time it's for keeps!

    This only occurs when the input is from a tty. It is likely because of the terminal settings where characters are buffered until a newline (carriage return) is entered.

提交回复
热议问题