Python EOF Error in raw_input()

前端 未结 3 1115
旧时难觅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条回答
  •  猫巷女王i
    2020-12-10 22:23

    This works under windows (I tested it by running python cons.py < cons.py and was able to see the prompt and not get an error about EOF):

    import sys
    
    for line in sys.stdin:
        print line
    
    sys.stdin = open('CON', 'r')
    q = raw_input('---->')
    

    Under Unix, you'd probably just have to replace 'CON' with something in the /dev dir.

提交回复
热议问题