[Tutor] How can I clean the screen

Suri Chitti SChitti at manh.com
Mon Jan 23 12:30:07 CET 2006

I tried os.system('cls')...the screen seemed to hang.

-----Original Message-----
From: Alan Gauld [mailto:alan.gauld at freenet.co.uk] 
Sent: Monday, January 23, 2006 3:37 PM
To: Suri Chitti; tutor at python.org
Subject: Re: [Tutor] How can I clean the screen

>            If I am executing a python prog from the command line and
> need to clear the screen (like using the cls command at the windows

Thus should be a FAQ somewhere...

Clearing the screen is terminal specific so Python doesn't have a single
to do it.
Since you mention Windows I'll assume thats what you are using and
simply use the CLS command via an os.system() call:

import os

If you have Linux substitute 'clear' for CLS

Or as a last resort write your own:

 def cls(rows=100):
     for row in rows: print

If you use curses it has a couple of functions for clearing a window.


Alan G.

More information about the Tutor mailing list