![](/img/trans.png)
[英]How to clear the output everytime run code in VSCode? I'm using terminal in VSCode to run
[英]VSCode: how to automatically clear Python terminal output window before each run using VS Code tasks?
我在 Mac OS X 的 VS Code 上。有没有一种方法可以让 VS Code 自动清除终端 window,每次运行它时,它都会从 Python 程序中显示 output? 我想在执行前清除终端 window。
编辑:查看建议的链接,我想使用 VS 代码任务来完成此操作。 我看到我需要编辑 .vscode 目录中的 tasks.json 文件,但是每次运行 Python 文件之前我如何触发任务,以及我要为任务填写哪些其他参数?
这里还是有点迷糊。 我应该为"command"
和"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"
}
]
}
在 Linux 中我们使用:
import os
os.system("clear")
您可以简单地导入 os 并使用命令清除终端。
对于 Windows:
import os
os.system("cls")
VS Code 为开发者提供了这种机制,用于 go 进一步的数据比较和代码改进。 如果你只是想展示output没有交互操作,试试这个:
Code Runner
ctrl+,
打开 setting.json 并添加 "code-runner.clearPreviousOutput": truerun code
以激活扩展Code
并单击按钮运行您的文件,如下图: sample ,然后每次运行您的项目,output 将被清除并显示最新结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.