简体   繁体   中英

Deleting blank lines from Jupyter notebook

Is there an easy way of removing blank lines from IPython notebook?

I have picked up a habit of blank lines from web development and my fingers tend to hit enter automatically. This makes IPython notebooks less(by taking too much of my 14" screen), not more readable in most cases.

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?

EDIT: I think question 2, Is answered by IPython docs. 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.

You can also see all the keyboard shortcuts in the jupyter notebook file在此处输入图片说明

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. It won't delete any lines which have some text or code.

Pressing Esc and D (2 times) deletes the complete cell.

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"

Ans: ctrl-d (in Edit mode)

Using a Mac:

  • to forward delete a line from the curser use Fn + command + delete
  • to backward delete a line from the curser use command + delete
  • to delete a whole cell use Esc + (d twice)

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+Backspace can be used to delete whole text of line before cursor position.

Similarly Ctrl+Delete to delete text after cursor.

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

If you came here looking for "How to delete a single line (whether code line or blank line) in a jupyter notebook cell"

ctrl-d (in Edit mode)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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