From: Daniel Fetchinson on
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?

Cheers,
Daniel


--
Psss, psss, put it down! - http://www.cafepress.com/putitdown
From: Bruno Desthuilliers on
Daniel Fetchinson a �crit :
> 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.
From: Grant Edwards on
On 2010-07-27, Bruno Desthuilliers <bruno.42.desthuilliers(a)websiteburo.invalid> wrote:
> Daniel Fetchinson a ?crit :
>> 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).

No, what he's talking about is clearing a terminal (or a terminal
emulator). They both work the same, the only difference is whether
the terminal software is running on dedicated hardware or on
general-purpose hardware.

> 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.

True, but clearing a terminal or terminal emulator has nothing to do
with the shell. It's done using an in-band control/escape sequence
that's indepedent of the shell being used. His example accomplishes
this using an executable named 'clear' which knows how to use
terminfo/termcap (I forget which one) to send the proper escape
sequence to the terminal.

> 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.

Again, the shell is irrelevent.

--
Grant Edwards grant.b.edwards Yow! Zippy's brain cells
at are straining to bridge
gmail.com synapses ...
From: Bruno Desthuilliers on
Grant Edwards a �crit :
> On 2010-07-27, Bruno Desthuilliers <bruno.42.desthuilliers(a)websiteburo.invalid> wrote:
>> Daniel Fetchinson a ?crit :
(snip)
>>> Why was clearing a terminal left out?
>>>
>> What you're talking about is a shell, not a terminal (a terminal is a
>> physical device).
>
> No, what he's talking about is clearing a terminal (or a terminal
> emulator). They both work the same, the only difference is whether
> the terminal software is running on dedicated hardware or on
> general-purpose hardware.

(snip)

I stand corrected.
From: Daniel Fetchinson on
>>> 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