Python 3: EOF when reading a line (Visual Studio Code)

纵饮孤独 提交于 2021-01-28 04:11:33

问题


I use visual studio code to program in Python, and whenever I try to take user input, Visual Studio Code throws me an "EOF when reading a line" at that specific line. However, this code works perfectly in command line and Python IDLE.

Side note: Python 3: EOF when reading a line (Sublime Text 2 is angry) is possibly a related question, as the error I am facing seems quite similar, only I am receiving this error in VSC and not Sublime text 2.

I think this might be because VSC has no valid way to take user input, any clarification or suggestion on alternate platforms are welcome.

Details:

Coding language: Python 3.8

Text Editor: Visual Studio Code

Code causing the problem:

number = int(input('Enter a number:    '))
print (number**2)

Error recieved:

Exception has occurred: EOFError
EOF when reading a line
  File "<location>", line 1, in <module>
    number = int(input('Enter a number:    '))

回答1:


I reproduced the problem you described:

Reason: When we use "console": "internalConsole", the result will be output to "DEBUG CONSOLE", and this terminal of VSCode is currently only used for display output. When the code needs to be input but input is not received, it will throw "EOF" "(End of file), "There is an unexpected error at the end of the file".

Solution: please change the output mode of the debugging code. (in settings.json file)

  1. For the code that needs to be entered, we can use "console": "integratedTerminal",

  2. or use "console": "externalTerminal",

Reference: console in VSCode.



来源:https://stackoverflow.com/questions/65046361/python-3-eof-when-reading-a-line-visual-studio-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!