开发者

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.sys开发者_如何学Pythontem('CLS'), but is there a way to do this without having to import all of os?


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.


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


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


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

cls

On Windows, and on *nix:

clear


for me, just to type "clear" is enought.


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 '


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

You need to import os first though:

import os


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.


__import__('os').system("reset")


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜