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.
Just enter
Wiper is cool, good thing about it is I don't have to type '()' around it. Here is slight variation to it
The usage is quite simple:
I might be late to the part but here is a very easy way to do it
Type:
So what ever you want to clear the screen just type in your code
Best way possible! (Credit : https://www.youtube.com/watch?annotation_id=annotation_3770292585&feature=iv&src_vid=bguKhMnvmb8&v=LtGEp9c6Z-U)
UPDATE: 80x25 is unlikely to be the size of console windows, so to get the real console dimensions, use functions from pager module. Python doesn't provide anything similar from core distribution.
Use idle. It has many handy features. Ctrl+F6, for example, resets the console. Closing and opening the console are good ways to clear it.
I'm not sure if Windows' "shell" supports this, but on Linux:
print "\033[2J"
https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_codes
In my opinion calling
cls
withos
is a bad idea generally. Imagine if I manage to change the cls or clear command on your system, and you run your script as admin or root.