且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在执行脚本之前自动清除 VSCode 中的终端?

更新时间:2023-12-04 19:13:28

基于@Jacques 答案,您可以使用 sys 模块动态执行平台检查:

Building on @Jacques answer, you can use the sys module to dynamically perform a platform check:

import os
import sys

# Linux
if sys.platform.startswith('linux'):
    os.system('clear')
# Windows
elif sys.platform.startswith('win32'):
    os.system('cls')

或者,请参阅这篇关于配置 vscode 为所有程序执行此操作的帖子:如何在开始构建时自动清除 VS Code 终端?

Alternatively, see this post on configuring vscode to do this for all programs: How do I automatically clear VS Code terminal when starting a build?