【问题标题】:No output in Output Panel when running code - Python on VSCode运行代码时输出面板中没有输出 - VSCode 上的 Python
【发布时间】:2020-08-16 19:06:17
【问题描述】:

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

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

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

print("Hello World")

【问题讨论】:

    标签: python python-3.x visual-studio-code vscode-settings


    【解决方案1】:

    如果您想在调试控制台中显示结果,您可以在文件夹.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

    【讨论】:

    • 这正是我一直在寻找的,甚至无数次的谷歌搜索,关键词的所有组合和排列都无法帮助我找到这个。非常感谢您的参与!非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-17
    • 2021-02-28
    • 1970-01-01
    • 2022-01-03
    • 1970-01-01
    相关资源
    最近更新 更多