当 运行 代码 - Python on VSCode 时,输出面板中没有输出

No output in Output Panel when running code - Python on VSCode

Python 和 Whosebug 的新手。如有遗漏,请见谅。

我刚刚创建了一个单行程序来打印 Hello World 但每次我 运行 程序(使用 F5 或转到 运行->Start Debugging)程序 运行s 和底部的面板自动切换到终端 window 并且输出显示在那里而不是在调试 window 中。 (图1)

在终端 window 中打印了很多其他内容,这就是为什么我只想在调试 window 中打印输出。另外,这就是我正在做的课程视频中显示的方式(图2)。

print("Hello World")

如果您想在调试控制台中显示结果,您可以打开文件夹 .vscode 中的文件 launch.json 并添加此设置:"console": "internalConsole",。 (或者打开调试按钮旁边的设置模式打开launch.json文件。)

这是我的 launch.json 文件的完整内容:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Python: Current File",
      "type": "python",
      "request": "launch",
      "program": "${file}",
      "console": "internalConsole",        
    }
  ]
}

然后,通过测试,将结果显示在调试控制台中。像这样:

参考:Python debug configurations in VSCode.