[Tutor] How can I clean the screen

Alan Gauld alan.gauld at freenet.co.uk
Mon Jan 23 11:07:09 CET 2006


>            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 cmd

Thus should be a FAQ somewhere...

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

import os
os.system('CLS')

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.

HTH,

Alan G.



More information about the Tutor mailing list