Python 3:读取行时EOF(Visual Studio代码) [英] Python 3: EOF when reading a line (Visual Studio Code)

查看:308
本文介绍了Python 3:读取行时EOF(Visual Studio代码)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Visual Studio代码在Python中进行编程,每当我尝试接受用户输入时,Visual Studio Code就会向我抛出读取行时的EOF".在该特定行.但是,此代码可在命令行和Python IDLE中完美运行.

旁注:

原因::当我们使用"console":"internalConsole"时,结果将输出到" DEBUG CONSOLE ";,并且VSCode的此端子当前仅用于显示输出.当需要输入代码但未接收到输入时,它将抛出" EOF "."(文件末尾),文件末尾有意外错误".

解决方案::请更改调试代码的输出模式.(在 settings.json 文件中)

  1. 对于需要输入的代码,我们可以使用"console":"integratedTerminal",

  2. ,或使用控制台":"externalTerminal",

参考:VSCode中的控制台.

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:    '))

解决方案

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.

这篇关于Python 3:读取行时EOF(Visual Studio代码)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆