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?

Logo

开发云社区提供前沿行业资讯和优质的学习知识,同时提供优质稳定、价格优惠的云主机、数据库、网络、云储存等云服务产品

更多推荐