sys.stdin.readlines() hangs Python script

前端 未结 4 781
南方客
南方客 2020-12-16 17:59

Everytime I\'m executing my Python script, it appears to hang on this line:

lines = sys.stdin.readlines()

What should I do to fix/avoid thi

4条回答
  •  臣服心动
    2020-12-16 18:17

    If you're running the program in an interactive session, then this line causes Python to read from standard input (i. e. your keyboard) until you send the EOF character (Ctrl-D (Unix/Mac) or Ctrl-Z (Windows)).

    >>> import sys
    >>> a = sys.stdin.readlines()
    Test
    Test2
    ^Z
    >>> a
    ['Test\n', 'Test2\n']
    

提交回复
热议问题