[Python-ideas] Suggestion: Clear screen command for the REPL

Stephen J. Turnbull turnbull.stephen.fw at u.tsukuba.ac.jp
Sun Sep 18 23:51:58 EDT 2016


Chris Angelico writes:
 > On Mon, Sep 19, 2016 at 12:32 PM, Steven D'Aprano <steve at pearwood.info> wrote:
 > > (The fallback if all else fails is easy: get the height of the terminal,
 > > in lines, and print that many blank lines.)
 > 
 > Assuming you can get the height in lines. Have you tried that in the
 > default Windows shell? I don't think tcgetattr works on Windows.

Since a command is out of the question (look what happened to print!),
it's a matter of defining a callable with a repr that explains how to
call it (like help and friends).  So if someone really wants this to
happen, I would say the thing to do is to define that callable, put it
on PyPI, add support for all the platforms, fix all the bugs, and when
there are a couple million downloads, suggest preloading it in
interpreter then.  Don't forget how to document how to add it to
site.py.

But I would think that nowadays we'd push in the opposite direction
(as with print).  That is, with the great improvements in IDLE
(batteries included!), IPython, and now we have Jupyter, you could now
argue that the built-in REPL should lose at least one of the two exit
functions (since EOF is a sufficient reason to exit).  (help() still
makes sense as the public interface to __doc__.)

In other words, the built-in REPL should just provide some
line-editing features and otherwise simply read lines, incrementally
compile and execute them, and print results.  Leave UI conveniences to
other applications that (gasp!) specialize in providing consistent,
powerful UI that isn't going to feel like bat guano on Tim's keyboard.
IMHO YMMV, of course.



More information about the Python-ideas mailing list