简体   繁体   English

VS Code 调试控制台不适用于 Python input()

[英]VS Code debug console won't work with Python input()

I have some simple code that works fine everywhere except the Debug Console on VS Code.我有一些简单的代码,除了 VS Code 上的调试控制台之外,它在任何地方都可以正常工作。

Here it is:这里是:

pounds = int(input("How much do you weigh in pounds? "))
kilos = pounds * 0.45359237
print("You weight " + str(kilos) + " kilograms.")

If you use the launch.json configuration of "console": "internalConsole", , then the output will go to the debug console, which doesn't work.如果你使用launch.json配置"console": "internalConsole", ,那么输出会到调试控制台,这不起作用。 If you do "console": "integratedTerminal" , the output will work and it will go to the terminal, but, it will make a new debug console each time, and eventually it will stop working on the 33 time.如果你做"console": "integratedTerminal" ,输出会工作,它会进入终端,但是,它每次都会创建一个新的调试控制台,最终它会在第 33 次停止工作。 I have the screenshot below.我有下面的截图。 The error is not shown in the terminal, but in a pop-up.该错误未显示在终端中,而是显示在弹出窗口中。 The error states:错误指出:

The terminal process "C:\\Program Files\\Git\\bin\\bash.exe" terminated with exit code: 256.终端进程“C:\\Program Files\\Git\\bin\\bash.exe”以退出代码:256 终止。

So there are two problems:所以有两个问题:

  1. Debug console won't work with input()调试控制台不适用于input()
  2. Terminal makes too many debug consoles, causing it to error.终端生成过多的调试控制台,导致它出错。

I am confused as to how anyone uses python on VS code, because I can't even get it to work.我对任何人如何在 VS 代码上使用 python 感到困惑,因为我什至无法让它工作。 I guess I can delete the consoles each time it reaches 33, but that seems inefficient and not how VS Code was intended to be used.我想我可以在每次达到 33 时删除控制台,但这似乎效率低下,而不是 VS Code 的用途。

screenshot:截屏: 在此处输入图片说明

  1. According to the information you provided, when I use "console": "integratedTerminal" in VSCode, the results will be executed sequentially in the same terminal:根据你提供的信息,当我在VSCode中使用"console": "integratedTerminal"时,结果会在同一个终端依次执行:

    在此处输入图片说明

  2. When using "internalConsole" , the result will not be executed normally, because currently the debugging console in VSCode is only used to display output.使用"internalConsole" ,结果不会正常执行,因为目前 VSCode 中的调试控制台仅用于显示输出。

  3. In addition, we can also use "console": "externalTerminal" , which can also accept input:此外,我们还可以使用"console": "externalTerminal" ,它也可以接受输入:

    在此处输入图片说明

Reference: console in VSCode .参考: VSCode 中的控制台

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM