Clearing the screen in IPython

Question:

Is there a command in IPython to clear the screen?

EDIT: As @Saher mentions below, I can clean the screen using import os; os.system('CLS'), but is there a way to do this without having to import all of os?

Answers:

If you are running windows try os.system('CLS')

You need to import os first though:

import os
Answered By: Saher Ahwal

You can bind it to the common Ctrl-l shortcut by putting this into your ~/.ipython/ipythonrc:

readline_parse_and_bind "C-l": clear-screen
Answered By: Jakub Roztocil
__import__('os').system("reset")
Answered By: Dan D.

To clear the screen on Windows, use !CLS.

On Unix-like systems, use !clear.

A shell command is executed by the operating system if prepended by an exclamation mark. See http://ipython.readthedocs.io/en/stable/interactive/reference.html#system-shell-access.

Note that commands should also work without the exclamation mark if they are defined as aliases. See http://ipython.readthedocs.io/en/stable/interactive/shell.html?#aliases.

There is also a Ctrl+L shortcut for clearing the screen. See http://ipython.readthedocs.io/en/stable/config/shortcuts/index.html#single-filtered-shortcuts.

Answered By: mzjn

clear is a default alias in ipython 0.11

In [76]: a = get_ipython()

In [77]: a.alias_manager.expand_alias('clear')
Out[77]: u'clear '
Answered By: Alex Gaudio

Maybe I’m just using a newer version, but it worked fine for me with just:

cls

On Windows, and on *nix:

clear
Answered By: A T

for me, just to type “clear” is enought.

Answered By: Mauro

CTRL + L works in both Windows and Ubuntu. And I guess it’s best because you don’t have to type much.

Answered By: lu5er

In macOS 10.13.1, Terminal 2.8, press command-k for Clear to Start.

clear resulted in “NameError: name ‘clear’ is not defined.”

Caution: As a noob I may not fully understand what I did, but command-k seemed to do what I intended.

Answered By: Charlie Ahern

On windows using Enthought Canopy Clear, CLS, !CLS, does not clear the previous data, it just moves all the data to above the top of the window. If you scroll down the text is all there.

Answered By: Ken Weiner

On Windows Powershell cls (in lowercase with no exclamation mark) clears the screen just fine.

Answered By: Omar T.
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.