python删除单元格快捷键,JupyterLab:如何使用键盘快捷键清除当前单元格的输出?

This question has been asked and answered for Jupyter Notebooks here. There is one suggestion regarding JupyterLab there as well on how to hide cell output, but not to clear it.

This is easy enough using the menu under Edit > Clear Outputs. But how do you do it using a keyboard shortcut? Many other commands under Edit already have their own assigned shortcuts, but not this one:

OEjOd.png

解决方案

The answer:

You'll have to assign a custom shortcut key under Settings > Advanced Settings Editor by inserting the following under User Preferences:

{// List of Keyboard Shortcuts

"shortcuts": [

{

"command": "notebook:clear-cell-output",

"keys": [

"F10"

],

"selector": ".jp-Notebook.jp-mod-editMode"

},

]

}

I went for F10, but most other keys or combination of keys should work too. I've also used Ctrl Shift Enter.

Where to put it:

pcUKD.png

Some details:

If you've assigned other shortcuts, make sure to add it in the correct place in the list of other shortcuts.

{// List of Keyboard Shortcuts

"shortcuts": [

{

"command": "notebook:run-in-console",

"keys": [

"F9"

],

"selector": ".jp-Notebook.jp-mod-editMode"

},

{

"command": "notebook:clear-cell-output",

"keys": [

"F10"

],

"selector": ".jp-Notebook.jp-mod-editMode"

},

]

}

And a little mystery:

If you insert the exact same thing as in the second box, you'll see that the item Run > Run Selected Text or Current Line in Console has gotten a nice F9 right next to it:

Shzf3.png

This will not be the case for the item Edit > Clear Outputs, and I'll have to say that I don't know why.

yVOMG.png

To my knowledge the "command": "notebook:clear-cell-output" that you're assigning to your chosen keyboard shortcut should be that exact functionality. But the good thing is that it works perfectly all the same. At least it does for me.

Please note that this approach works best for newer versions of JupyterLab. The correct way will be a bit different for older versions.

Here's a python snippet to test it out right away:

import pandas as pd

import numpy as np

df = pd.DataFrame(np.random.randint(0,100,size=(100, 4)), columns=list('ABCD'))

print(df)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值