Tharix Tharix - 2 years ago 326
Python Question

Python: Clear screen in shell

Just a quick question:

How do you clear the screen in shell?
I've seen ways like:

import os

This just opens the windows cmd, clears the screen and closes but
I want the shell window to be cleared

(PS: I don't know this helps, but I'm using version 3.3.2 of Python)

Thank you :)

Answer Source

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

import subprocess as sp'cls',shell=True)

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

tmp ='cls',shell=True)

For linux, you must replace cls command with clear

tmp ='clear',shell=True)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download