如何让VScode上的Python终端只显示输出

问题描述 投票:0回答:1

我最近才开始接触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 只显示输出吗?

python visual-studio visual-studio-code
1个回答
0
投票
  1. 确保Python已安装
  2. 要检查这一点,请打开 VS code,按
    ctlr+shift+X
    转到扩展并搜索 python 并确保它已安装。

python extension

  1. ctrl+shift+p
    打开命令选项板并键入任务。

  2. 选择

    Tasks: configure tasks
    ,然后选择
    Create tasks.json file from template
    ,然后选择
    other
    作为模板。

  3. 修改

    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": []
        }
    ]
    
    
  4. 运行任务:要使用此任务运行 Python 文件,请打开命令面板 (Ctrl+Shift+P) 并键入运行任务。选择运行 Python 文件。

© www.soinside.com 2019 - 2024. All rights reserved.