[Python-ideas] Suggestion: Clear screen command for the REPL
Terry Reedy
tjreedy at udel.edu
Sat Sep 17 15:43:02 EDT 2016
On 9/17/2016 6:51 AM, João Matos wrote:
> Hello,
>
> I would like to suggest adding a clear command (not function) to Python.
> It's simple purpose would be to clear the REPL screen, leaving the >>>
> prompt at the top left of the screen.
>
> This is something very basic but also very useful for newbies learning
> Python from the REPL.
> After some trial and errors it is best to start with a clean screen.
> Clearing the screen helps clear your mind.
>
> Historically it is a common command in interpreted languages.
Python is not an 'interpreted' language in the sense that you are using
the word. It is a compiled language that includes its compile function
as part of the runtime. This enables an interactive mode.
Python does not have commands, only statements, expressions, and
functions, etcetera. This is why the 'exit()' and 'quit()' 'commands'
are functions and require the parentheses. In interactive mode, a
statement consisting of a single indentifier (or expression) causes
display of a representation of the resulting object.
You could request that the site module also add a clear() function. But
the next problem is that clearing the screen is not a Python function
and the Python runtime does not normally know how to do so. The
implementation of 'clear screen' is specific to the particular console
or window or terminal emulation. The control sequence for a window that
emulates VT100 does not work on Windows Command Prompt (excepting
possibly a non-default CP on Win 10) or necessarily IDLE or IPython or
PyCharm or ... . The only assumption that Python makes about the screen
it is running on is that '\n' is interpreted as a newline.
IDLE has a 'Restart Shell' menu command with key binding. It does not
physically clear the screen but it draws a double line, which serves
most of the 'clear the mind' purpose. If there is an editor window
open, one can close and reopen the Shell window to start really fresh.
At least on Windows, Select All (^A) + Del (or Backspace) is the common
idiom for clearing an editor box in a GUI. Is this used on other OSes?
This works in an IDLE editor also. It is disabled in the Shell because
IDLE's original designers thought to protect beginners from doing such.
A clear screen menu option has been requested, but it has never become a
top priority. In any case, this, like other current clear screen
commands, would work because the command would go to the window manager
and not to python.
--
Terry Jan Reedy
More information about the Python-ideas
mailing list