温馨提示:本文翻译自stackoverflow.com,查看原文请点击:其他 - How to hide file paths when running Python scripts in VS Code?
python visual-studio-code vscode-settings

其他 - 在VS Code中运行Python脚本时如何隐藏文件路径?

发布于 2020-07-08 03:51:46

每次我运行代码时,底部的终端都会显示这个长名称(我认为是文件位置)以及应该显示的任何输出。

有没有办法使它消失?

看起来是这样的:

(正在发生的事情的屏幕截图)

administrator@Machintosh-2 Exercise Files Python % /user/bin/python3...
Hello world!  
administrator@Machintosh-2 Exercise Files Python %

查看更多

提问者
harrycoin
被浏览
26
Gino Mempin 2020-04-13 08:38

AFAIK,没有办法隐藏路径,因为VS Code集成终端基本上是使用OS /系统的基础终端。在终端上运行Python脚本通常需要:

<path/to/python/interpreter> <path/to/python/file>

如果您想要“更干净”的控制台输出,则可以为Python创建调试/启动配置,然后将console配置设置internalConsole

.vscode / launch.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "run-my-script",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/path/to/your_script.py",
            "console": "internalConsole"
        },
        ...
    ]
}

这将在“ 调试控制台”选项卡而不是“ 终端”选项卡中显示输出
无论您将脚本打印到控制台什么,都将没有更多路径。

样本输出

在此处输入图片说明