Why is there no platform independent way of clearing a terminal?
Grant Edwards
invalid at invalid.invalid
Tue Jul 27 10:32:52 EDT 2010
On 2010-07-27, Bruno Desthuilliers <bruno.42.desthuilliers at 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 ...
More information about the Python-list
mailing list