Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clearing the screen in IPython

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?

like image 403
Amelio Vazquez-Reina Avatar asked Sep 03 '25 14:09

Amelio Vazquez-Reina


2 Answers

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.

like image 180
mzjn Avatar answered Sep 05 '25 15:09

mzjn


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
like image 27
Jakub Roztocil Avatar answered Sep 05 '25 16:09

Jakub Roztocil