我最近才开始接触Python编程。在我看过的 YouTube 视频中,每次运行 Python 程序时,VS Code 终端仅显示输出。
在我的 VS Code 中,它还先显示两个窗口的目录,然后再显示输出,这是我不想看到的。以下是我在计算机屏幕上的代码: PS C:\Users\Bill\Desktop\Artificial Intelligence> &
C:/Users/Bill/AppData/Local/Programs/Python/Python312/python.exe "c:/Users/Bill/Desktop/Artificial Intelligence/Day 1 - Self-taught Py/snake.py"
1
有什么办法可以让 VS Code 只显示输出吗?
ctlr+shift+X
转到扩展并搜索 python 并确保它已安装。按
ctrl+shift+p
打开命令选项板并键入任务。
选择
Tasks: configure tasks
,然后选择 Create tasks.json file from template
,然后选择 other
作为模板。
修改
tasks.json
文件包含以下内容
"version": "2.0.0",
"tasks": [
{
"label": "Run Python File",
"type": "shell",
"command": "python",
"args": [
"${file}"
],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "always",
"echo": false,
"focus": false,
"panel": "shared"
},
"problemMatcher": []
}
]
运行任务:要使用此任务运行 Python 文件,请打开命令面板 (Ctrl+Shift+P) 并键入运行任务。选择运行 Python 文件。