Python raw_input following sys.stdin.read() throws EOFError

前端 未结 2 1341
不思量自难忘°
不思量自难忘° 2021-01-05 09:21

a similar question has been asked before, but the answers suggested a workaround which is not applicable to my situation.

An email message is piped from mutt to a sc

相关标签:
2条回答
  • 2021-01-05 09:59

    Have you tried this:

    message = sys.stdin.read()
    sys.stdin = open('/dev/tty')
    selected_index = raw_input('Which URL to open?')
    

    This works on Linux; maybe it will work for OSX too.

    0 讨论(0)
  • 2021-01-05 10:14

    Try to reset STDIN using sys.stdin.seek(0)

    Reference: http://docs.python.org/library/fileinput.html

    0 讨论(0)
提交回复
热议问题