Like most Python developers, I typically keep a console window open with the Python interpreter running to test commands, dir() stuff, help() stuff, etc.
Like any console, after a while the visible backlog of past commands and prints gets to be cluttered, and sometimes confusing when re-running the same command several times. I'm wondering if, and how, to clear the Python interpreter console.
I've heard about doing a system call and either calling cls
on Windows or clear
on Linux, but I was hoping there was something I could command the interpreter itself to do.
Note: I'm running on Windows, so Ctrl+L doesn't work.
As you mentioned, you can do a system call:
For Windows
For Linux the lambda becomes
You have number of ways doing it on Windows:
1. Using Keyboard shortcut:
2. Using system invoke method:
3. Using new line print 100 times:
Here's a cross platform (Windows / Linux / Mac / Probably others that you can add in the if check) version snippet I made combining information found in this question:
Same idea but with a spoon of syntactic sugar:
How about this for a clear
That is about as short as could be!
Here are two nice ways of doing that:
1.
2.
This should be cross platform, and also uses the preferred
subprocess.call
instead ofos.system
as per theos.system
docs. Should work in Python >= 2.4.