[Tutor] Clear Screen

dman dsh8290@rit.edu
Thu, 26 Jul 2001 12:42:20 -0400


On Thu, Jul 26, 2001 at 12:30:13PM -0400, fleet@teachout.org wrote:
| NO! WAIT!  I know how to do it!
| 
| I've written a function clear() as follows:
| 
| def clear():
|     import os
|     cls=os.popen("clear").read()
|     eval(cls)

eval()ing stuff can be dangerous unless you know what you are
eval()ing.  (Suppose you got 'open( "/file/to/destroy" , "w" )')

| It works fine except it leaves two lines at the top of the screen (a minor
| irritant - they usually display "SyntaxError" :) ).

That means that the stuff you got from the pipe to 'clear' wasn't a
valid Python expression.  Why do you want to eval() it?  Simply
os.system( "clear") will work.  Also note that it only works on Unix
systems -- DOS doesn't have a 'clear' command.

-D