gpt4 book ai didi

python - 运行代码时输出面板中没有输出 - VSCode 上的 Python

转载 作者:行者123 更新时间:2023-12-05 02:50:57 25 4
gpt4 key购买 nike

Python 和 StackOverflow 的新手。如果我错过任何手续,我深表歉意。

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

终端窗口中会打印很多其他内容,这就是为什么我只想在调试窗口中打印输出。另外,这就是我正在做的类(class)视频中显示的方式(图 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

最佳答案

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

引用:Python debug configurations in VSCode .

关于python - 运行代码时输出面板中没有输出 - VSCode 上的 Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63440932/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com