2

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:    '))
Codeman
  • 477
  • 3
  • 13

3 Answers3

3

I reproduced the problem you described:

enter image description here

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",

    enter image description here

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

    enter image description here

Reference: console in VSCode.

Jill Cheng
  • 9,179
  • 1
  • 20
  • 25
1

Using the Microsoft Visual Studio Code (and the debug window for code that does not require input), I right-clicked on the code and from the submenu selected the Run Python File in Terminal option. Rather than executing in the Debug tab, it executed in the Terminal tab. I was able to enter an input there and test the input value.

enter image description here

karel
  • 5,489
  • 46
  • 45
  • 50
Paul
  • 11
  • 1
-1

This problem also happened to me. I ran the program with the terminal. At the top right corner, there should be a dedicated button that does so.

  • Hello, this is no answer. You should delete this ... – Kraego Jan 17 '22 at 11:25
  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/30836269) – joanis Jan 20 '22 at 13:52