[Tutor] Clear Screen

Kalle Svensson kalle@gnupung.net
Thu, 26 Jul 2001 18:45:13 +0200


Sez fleet@teachout.org:
> I've written a function clear() as follows:
> 
> def clear():
>     import os
>     cls=os.popen("clear").read()
>     eval(cls)

Why eval?  eval() takes a string argument and evaluates it as a python
expression.  Most often, the output of the system "clear" command isn't a
valid python expression... <wink>
My guess is that you really want

def clear():
    import os, sys
    cls = os.popen("clear").read()
    sys.stdout.write(cls)

or, perhaps even better

def clear():
    import os
    os.system("clear")

This version can also be called cls without problems.

Peace,
  Kalle
-- 
Free Dmitry Sklyarov! - http://www.freedmitry.org/