How do i automatically clear the terminal in VSCode before execution of script? [duplicate]
Answer a question
I am currently using VS Code to learn Python . So i have to run scripts like 10-15 times a minute , just doing small edits and learning all things. I am running the scripts in integrated terminal of VS code
So apparently the terminal gets horribly cluttered and i have to always clear the terminal manually by running clear, I want the terminal to automatically get cleared every time I execute the Python script . Please note that I am not looking for a keyboard shortcut to clear terminal , rather I need the terminal to automatically clear the old output before displaying the output of the present script. I couldn't find anything that does this , hopefully someone can provide a way out
Answers
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')
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?
更多推荐
所有评论(0)