How to hide file paths when running Python scripts in VS Code?

混江龙づ霸主 提交于 2021-01-28 00:34:26

问题


Every time I run my code, the terminal at the bottom is displaying this long name (I think the file location) as well as whatever output it's supposed to display.

Is there a way to get that to go away?

This is what it looks like:

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

回答1:


AFAIK, there is no way to hide the paths, because the VS Code Integrated Terminal is basically using your OS/system's underlying terminal. And running Python scripts on a terminal usually requires:

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

If you want a "cleaner" console output, you could create a debug/launch configuration for Python, then set the console configuration to 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"
        },
        ...
    ]
}

That would display the output in the Debug Console tab rather than the Terminal tab.
There will be no more paths, just whatever your script prints out to the console.

sample output:



来源:https://stackoverflow.com/questions/61176552/how-to-hide-file-paths-when-running-python-scripts-in-vs-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!