Clear screen in shell Clear screen in shell python python

Clear screen in shell


What about the shortcut CTRL+L?

It works for all shells e.g. Python, Bash, MySQL, MATLAB, etc.


import osos.system('cls')  # For Windowsos.system('clear')  # For Linux/OS X


For macOS/OS X, you can use the subprocess module and call 'cls' from the shell:

import subprocess as spsp.call('cls', shell=True)

To prevent '0' from showing on top of the window, replace the 2nd line with:

tmp = sp.call('cls', shell=True)

For Linux, you must replace cls command with clear

tmp = sp.call('clear', shell=True)