运行Python代码在VSCode中无法在输出面板中输出结果

3

我刚学习Python和StackOverflow,如果有任何疏忽请见谅。

我创建了一个简单的程序来打印“Hello World”,但每次运行程序(使用F5或转到“运行” -> “开始调试”),程序会运行,并且底部面板会自动切换到终端窗口,输出将在那里显示而不是在调试窗口中显示。(图片1)

许多其他内容都会在终端窗口中打印,这就是为什么我只想在调试窗口中打印输出的原因。此外,这正是我正在学习的课程视频中所演示的方式。(图片2)

print("Hello World")

My Debug window with no output of the program

Screenshot of the Course Video Output as it appears on the Debug Window

1个回答

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

enter image description here

这是我的launch.json文件的完整内容:
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Python: Current File",
      "type": "python",
      "request": "launch",
      "program": "${file}",
      "console": "internalConsole",        
    }
  ]
}

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

enter image description here

参考:VSCode中的Python调试配置

这正是我一直在寻找的,即使进行了无数次使用关键字的各种组合和排列进行谷歌搜索也无法帮助我找到它。 非常感谢您的时间!非常感激。 - Darka

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接