Python EOF Error in raw_input()

前端 未结 3 1111
旧时难觅i
旧时难觅i 2020-12-10 21:31

I am trying to get input from the user at the command prompt. The program reads in data from a text file in the manner of \"cat text.txt | ./thescript.py\"

At the

3条回答
  •  既然无缘
    2020-12-10 22:32

    The objective is to have the script print a warning to standard error and let me choose whether to ignore the warning and continue or quit entirely.

    You want the choice to come from an interactive prompt, while the data comes from the file? Well, now you're doing something different from the original program: you're reading those two things from different places, where they came from the same place before. So you need to update your design to allow for that.

    Why does the raw_input not wait for input

    raw_input waits for as long as is necessary to get a line of input. If the standard input is being redirected from a file, then lines of input are always available immediately (well, limited by e.g. the hard disk speed), up until the EOF, at which point no more will ever be available. In short, it doesn't wait for you to answer the question for the same reason that it doesn't wait for you to supply the invoice data: because you aren't the data source any more once you redirect from the file.

提交回复
热议问题