Issue
How do you clear the screen in shell?
I've seen ways like:
import os
os.system('cls')
This just opens the Windows cmd, clears the screen and closes but I want the shell window to be cleared.
I'm using version 3.3.2 of Python.
Solution
For macOS/OS X, you can use the subprocess module and call 'cls' from the shell:
import subprocess as sp
sp.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)
Answered By - GalHai Answer Checked By - Mildred Charles (WPSolving Admin)