[Tutor] Clearing the Console Screen

Alan G alan.gauld at freenet.co.uk
Thu Jun 16 23:40:49 CEST 2005


> Don Parris wrote:
> > Thanks!  I thought there had to be a way to call the OS' clear
screen
> > command, but was going about it the wrong way.  I was trying to
use
> > sys.clear instead of os.system.  Would it be difficult to test the
OS,
> > store the result in a variable, and call the comand based on the
variable
> > result?  Or would it be simpler to have users edit the script for
their OS?

You can do that and I think thats what Fred Lundh's console program
does but its not as simple as that either. Some terminals won't
respond to the os clear - for example som Textronic displays
only clear in text mode but when in graphics mode (and many folks
use them thus to use nicer fonts) they won't clear with 'clear'.
The only way to do it is send the graphics control characters...

>  beginning to get an idea of the challenges of portability though.
;)

Portability is a real pain. You can achieve 95% portability
with only minimal effort but complete portability (think Palm,
Paper teletype, Mainframe 3270 terminal, embedded browser
interpreter etc etc) is a very elusive goal indeed.

On Unix(*) you do have one other option however which is to use
curses.
This is a pseudo windowing system which runs on character terminals.
It has a default window of the whole screen and allows accurate
cursor placement, character deletion, screen clearing, instant
character reading etc etc. Its a bit  irksome to set up but
once initialised not too hard to use. If your app does a lot
of screen control - like vim or emacs say, then curses is probably
the right approach.

(*) There is a DOS curses available for download but I
couldn't get it to work properly. The *nix curses module
is part of the standard library. (THere is also an O'Reilly
book on ncurses - the C version, and several online
tutorials for the C version too. The Python module is a
pretty straight translation of the C API to Python.)

Alan G.




>
> Python actually gets a lot of this right, you may find it's easier
than you think to write portable Python.
>
> Kent
>
>
>



More information about the Tutor mailing list