On Sun, Dec 20, 2020 at 1:23 PM Cameron Simpson email@example.com wrote:
On 20Dec2020 08:51, Christopher Barker firstname.lastname@example.org wrote:
On Sat, Dec 19, 2020 at 8:53 PM Guido van Rossum email@example.com
at sounds like a very special status. Why not os.clear()?
My anger at programmes which gratuitously clear the screen is large.
There are a LOT of bad things one can do with Python, I don't think we need to make something difficult simply because it can be abused.
One problem is: what does it mean? On a terminal, easy. But in a GUI?
Clear the screen (possibly forbidden)? A window? The "main" window? Etc.
It would be meaningless outside of a terminal -- call it `clear_term` if you want. Even print() doesn't have a consistent useful meaning in a GUI program.
Anyway, I think it should be in curses (or be loaded via curses on
That would be great, though I just looked at the 3.9 docs and saw: "The Windows version of Python doesn’t include the curses module."
So we're pretty much back to square one.
I think the idea here is that we want a simple way, out of the box that people can use to clear the terminal, that will work on most commonly configured systems out of the box, and can be overridden (monkey patched) to work in IDEs (e.g. Idle), custom terminal emulators (e.g. iPython Qtconsole), etc. We don't want to require a full curses implementation.
and just have a clear_screen function thus:
def clear_screen(): setupterm() print(ti_getstr('cl'), end='', flush=True)
I just tried that on my mac and tigetstr('cl') simply returns None with no effect.
I've only looked for a coupe minutes, but it seems you need to set up curses in order ot use it, so maybe not teh best way to go for a single action?
The tutorial seems to indicate there is a clear method available, so I did try that, and it does nothing on my Mac with the default terminal app:
def clear_screen(): from curses import wrapper
def clr(stdscr): # Clear screen stdscr.clear() wrapper(clr) clear_screen()
I may have done something wrong, so anyone please correct -- but it's sure looking to me like curses is not a solution to this problem.
here is that this is trivial function
clearly not trivial to write for someone new to curses :-)
On terminals, see above. In a GUI, who knows? And how does one tell the programme which it is talking to?
That would be up to the GUI toolkit to provide if it includes a terminal emulator of some sort.
is it so bad to use a subprocess?
Yes. It is _really slow_,
could it possible be slow enough to matter? not the kind of thing that's in a tight loop.
depends on external reaources which might not
oh, like the curses lib ;-)
and subprocess brings other burdens too. Python comes with curses and that knows directly how to do this.
not that I could figure out, and apparently not on Windows.
Anyway, the idea (I have) is that this would be somewhere like os.clear_term(), and the implementation would be platform specific -- if on *nix systems, it used curses, great!
The other thought is that this has been in iPython, with the simple os.system() implementation, for years, so it eather works well enough, or no one ever uses it :-)
I looked at iPython issues, and apparently there is (or was) an issue with Windows if the current working dir is a network mount, but that's all I found. Of course, there are 1400 open issues, so I may have missed one :-)
Anyway, not my area of expertise, I just think it's a good idea if someone with the appropriate expertise wants to step up and write it.