I know there's a similar topic about python console, but I do not know if they are the same. I tried system("clear") and it didn't work here.
How do I clear python's IDLE window?
I know there's a similar topic about python console, but I do not know if they are the same. I tried system("clear") and it didn't work here.
How do I clear python's IDLE window?
os.system('clear')
works on linux. If you are running windows tryos.system('CLS')
instead.You need to import os first like this:
Whenever you wish to clear console call the function cls, but note that this function will clear the screen in Windows only if you are running Python Script using cmd prompt, it will not clear the buffer if you running by IDLE.
Most of the answers appear here do clearing the DOS prompt screen clearing commands. Which is not the Question asked here. An other answer here posted was the printing blank lines to show a clearing effect of the screen.
The simplest answer of this question is
The way to execute commands in Python 2.4+ is to use the subprocess module. You can use it in the same way that you use
os.system
.If you're executing this in the python console, you'll need to do something to hide the return value (for either
os.system
orsubprocess.call
), like assigning it to a variable:None of these solutions worked for me on Windows 7 and within IDLE. Wound up using PowerShell, running Python within it and exiting to call "cls" in PowerShell to clear the window.
CONS: Assumes Python is already in the PATH variable. Also, this does clear your Python variables (though so does restarting the shell).
PROS: Retains any window customization you've made (color, font-size).
I like to use: