Ipython Notebook: Elegant way of turning off part of cells?

Using Jupyter notebook you can click on a cell, press esc and then r. That converts it to a "raw" cell. Similar thing can be done to convert it back, esc + y. No comments needed, just key presses.

Within Jupyer notebook, go to Help -> Keyboard shortcuts for more.

Here's a snippet:

Command Mode (press Esc to enable)

  • ↩ : enter edit mode

  • ⇧↩ : run cell, select below

  • ⌃↩ : run cell

  • ⌥↩ : run cell, insert below

  • y : to code

  • m : to markdown

  • r : to raw


You can use a condition at the cost of one extra indentation.

cellEnabled = 0
#cellEnabled = 1

if cellEnabled:
    doA()
    doB()

In Jupyter notebooks one can use this magic preamble at the beginning of a cell to avoid its execution:

%%script false --no-raise-error