问题
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