[Tutor] How can I clean the screen

Ivan Furone mail.roma1 at gmail.com
Mon Jan 23 14:17:07 CET 2006


2006/1/23, Suri Chitti <SChitti at manh.com>:
>
> Dear group,
>            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
> prompt) midway into the program, how do I do it??  Any inputs will be
> greatly appreciated.
> Thanks.
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>

Hi there
A nice neat trick which is:

print '\n' * 100

Will print a hundred lines on the screen,thus shifting the cursor down
so the screen will seem to have been cleaned.

Or it's possible to implement these lines in a program:

 import os, platform
 def clear_screen():
  if platform.system() == 'Linux': os.system('clear')
  if platform.system() == 'Windows': os.system('cls')
 clear_screen()

(Both them are excerpt from the Python Tips and Tricks published from
the Italian Python User Group).
Cheers
Ivan


More information about the Tutor mailing list