Why is there no platform independent way of clearing a terminal?

Daniel Fetchinson fetchinson at googlemail.com
Tue Jul 27 12:58:14 EDT 2010


>>> Hi folks,
>>>
>>> If I'm only interested in linux and windows I know I can do
>>>
>>> ################################
>>> import os
>>> import platform
>>>
>>> if platform.system( ) == 'Linux':
>>>     clear = 'clear'
>>> else:
>>>     clear = 'cls'
>>>
>>> os.system( clear )
>>> ################################
>>>
>>> or something equivalent using os.name and friends, but was wondering
>>> why there is no platform independent way (i.e. the platform dependence
>>> is taken care of by the python stdlib) of clearing a terminal. Sure,
>>> there are many different terminals and many different operating
>>> systems but in many areas python managed to hide all these
>>> complexities behind a well defined API.
>>>
>>> Why was clearing a terminal left out?
>>>
>>
>> What you're talking about is a shell, not a terminal (a terminal is a
>> physical device). And the shell is not necessarily part of the OS itself
>
>> (there's no shortage of shells for unices / linux systems), so it
>> doesn't belong to the os or platform modules.
>>
>> FWIW, I can't tell for sure since I never used any other shell than
>> bash, but I'm not sure your above code is garanteed to work on each and
>> any possible unix shell.
>
> Sorry, but that is completely wrong - the shell is irrelevant.
>
> "clear" is just a normal command line program that queries the
> termcap/terminfo database (possibly via the curses library) for the
> terminal specific sequence of characters that will clear the screen. It
> then writes those characters to stdout. The terminal, or (more usually
> these days) terminal emulator, then interprets those characters and takes
> the appropriate action.
>
> I'm not sure what the POSIX status of the clear command is, but I'd be
> surprised if it wasn't present on a UNIX/Linux system of any vintage.


After getting the technicalities out of the way, maybe I should have asked:

Is it only me or others would find a platform independent python API
to clear the terminal useful?

Cheers,
Daniel


-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown



More information about the Python-list mailing list