简体   繁体   English

从 Jupyter 笔记本中删除空行

[英]Deleting blank lines from Jupyter notebook

Is there an easy way of removing blank lines from IPython notebook?有没有一种简单的方法可以从 IPython 笔记本中删除空行?

I have picked up a habit of blank lines from web development and my fingers tend to hit enter automatically.我从 Web 开发中养成了空行的习惯,我的手指倾向于自动按 Enter。 This makes IPython notebooks less(by taking too much of my 14" screen), not more readable in most cases.这使得 IPython 笔记本更少(通过占用太多我的 14 英寸屏幕),在大多数情况下不更具可读性。

I was wondering if there is a way of automatically remove blank lines from the notebooks.我想知道是否有办法从笔记本中自动删除空行。

In notebooks, I think preferred way of splitting the code is by placing each separate method to a different cell.在笔记本中,我认为拆分代码的首选方法是将每个单独的方法放置到不同的单元格中。

Is commonly accepted style guide for notebooks or does PEP 8 apply as it is?是普遍接受的笔记本风格指南还是 PEP 8 照原样适用?

EDIT: I think question 2, Is answered by IPython docs.编辑:我认为问题 2,由 IPython 文档回答。 https://github.com/ipython/ipython/wiki/Dev:-Coding-style https://github.com/ipython/ipython/wiki/Dev:-Coding-style

If you are talking about deleting the empty line from jupyter notebook which opens in web browser then press Esc and D(keyboard key) 2 times.如果您要从在 Web 浏览器中打开的 jupyter notebook 中删除空行,请按 Esc 和 D(键盘键)2 次。

You can also see all the keyboard shortcuts in the jupyter notebook file您还可以在 jupyter notebook 文件中看到所有键盘快捷键在此处输入图片说明

by clicking on the help and then from dropdown on keyboard shortcuts.通过单击帮助,然后从键盘快捷键的下拉菜单中。

Pressing Esc and D (2 times) will delete only blank lines starting from the beginning.按 Esc 和 D(2 次)将只删除从头开始的空白行。 It won't delete any lines which have some text or code.它不会删除任何包含一些文本或代码的行。

Pressing Esc and D (2 times) deletes the complete cell.Esc 和 D(2 次)删除整个单元格。

I guess the Question is about deleting the blank lines, unless the author interpretation of blank lines are blank cells.我想问题是关于删除空行,除非作者对空行的解释是空白单元格。

If you came here looking for "How to delete a single line (whether code line or blank line) in a jupyter notebook cell"如果您来这里是为了寻找“如何删除 jupyter 笔记本单元格中的单行(无论是代码行还是空白行)”

Ans: ctrl-d (in Edit mode)答案: ctrl-d(在编辑模式下)

Using a Mac:使用 Mac:

  • to forward delete a line from the curser use Fn + command + delete从光标中转发删除一行,使用 Fn + command + delete
  • to backward delete a line from the curser use command + delete从光标中向后删除一行,使用 command + delete
  • to delete a whole cell use Esc + (d twice)删除整个单元格使用 Esc + (d 两次)

These, and other shortcuts, can be found under the Help tab.这些和其他快捷方式可以在“帮助”选项卡下找到。

转到所需的行并按: ESC + D (一起两次

Use Ctrl+Backspace or Ctrl+Delete both will delete blank lines.使用Ctrl+BackspaceCtrl+Delete都将删除空行。

Ctrl+Backspace can be used to delete whole text of line before cursor position. Ctrl+Backspace 可用于删除光标所在行之前的整个文本。

Similarly Ctrl+Delete to delete text after cursor.同样 Ctrl+Delete 删除光标后的文本。

我认为问题是关于删除单元格的一个空的新行。我的解决方案是在要删除的行中写一些内容,然后转到其上方行的末尾并按删除直到行中写入的垃圾被删除被清除。这也会删除空的新行。

If you came here looking for "How to delete a single line (whether code line or blank line) in a jupyter notebook cell"如果您来这里是为了寻找“如何删除 jupyter 笔记本单元格中的单行(无论是代码行还是空白行)”

ctrl-d (in Edit mode) ctrl-d(在编辑模式下)

Select the row you want to delete and click the scissors icon highlighted in the below screenshot -选择要删除的行,然后单击以下屏幕截图中突出显示的剪刀图标 - 在此处输入图片说明

I'm pretty sure you just have to do it manually. 我很确定你必须手动完成它。 And you don't have to split code by putting it into different cells, in fact, I think its easy to not do that. 并且您不必通过将代码放入不同的单元格来拆分代码,事实上,我认为很容易做到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM