[Tutor] Clear screen questions

Alan Gauld alan.gauld at btinternet.com
Mon May 6 10:42:22 CEST 2013


On 06/05/13 01:17, boB Stepp wrote:

> os.system('cls' if os.name=='nt' else 'clear')
>
> So my main question is there a truly clean, cross-platform solution to
> the clear screen dilemma? If my online searching is accurate, then the
> answer appears to be no, unless one wants to print many blank lines.

Note that the issue is not strictly an OS issue but a terminal issue. 
Unix hides the terminal problems by using the terminfo database to 
standardize screen handling. Windows doesn't. So even CLS does not work 
for every kind of terminal you get on Windows. And the other solutions 
won't necessarily work on VMS or MVS or OS/390 etc.

You can usually clear the screen with an escape code but the code is 
terminal dependent. On DOS it usually uses the ANSI driver which may or 
may not be loaded. In an xterm it depends on whether you are using the 
VTx00 or the Tektronic emulation.

In other words it's much more complex than you would superficially 
expect and that's the reason cross platform languages like Python 
struggle to provide a solution.

Fred Lundh had a terminal module that tries to make common operations 
platform independent, but I'm not sure if its still supported. I don't 
know of anything that works within an IDE, for good reason - you don't 
want to clear the potentially useful debugging data that's on the
screen...

> something unexpected that I would like to understand. Upon hitting the
> clear screen code the active window switched from the Python shell
> window to the Python edit window. Why is this so?

No idea but worth asking on the IDLE list - its fairly active and they 
would probably be interested.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list