Reputation: 585
I'm on VS Code for Mac OS X. Is there a way that I can have VS Code automatically clear the terminal window that shows output from the Python program each time I run it? I'd like to clear the terminal window before execution.
Edit: Looking at the suggested links, I'd like to do this with VS Code tasks. I see that I'd need to edit the tasks.json file in the .vscode directory, but how would I trigger the task each time before the Python file is run, and what other parameters would I fill in for the task?
Still a little confused here. What do I put in for "command"
and "label"
?
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "echo Hello",
"clear": "true"
}
]
}
Upvotes: 5
Views: 10180
Reputation: 333
You can simply import os and clear the terminal with a command.
For Windows:
import os
os.system("cls")
Upvotes: 6
Reputation: 9521
VS Code provides this machanism for developers to go further data comparation and code improvation. If you just want to show the output without interactive operations, try this:
Code Runner
in extension marketplacectrl+,
to open setting.json and add "code-runner.clearPreviousOutput": truerun code
to activate the extensionCode
in the panel and click the button to run your file, like the following picture:
sample,
then every time you run your project, the output will be cleared and show the latest result.Upvotes: 2
Reputation: 10372
I tried what you said through the settings tasks.json. But I didn't find a places where terminal information can be automatically cleared before running Python files.
If you don't want to clear console information by entering commands, you could try these operations.
In addition, setting "console": "external terminal" in launch.json also opens a new cmd terminal every time you run a python file.
You can refer to:This.
Upvotes: 0