Skip to content

Ad-Hoc, Jupyter-like code "cells"

Note

  • Your environment must have the ipykernel package installed.
  • I have only tested this with VSCode. It should work in any IDE that supports ipykernel (i.e. JetBrains), from what I've read, but I have not tested it anywhere else.

You can create ad-hoc "cells" in any .py file (i.e. notebook.py, nb.py, etc) by adding # %% line(s) to the file.

Example 'notebook.py' file
# %%

You can also create multiple code cells by adding more # %% lines:

notebook.py
1
2
3
4
5
6
7
8
9
# %%
msg = "This code is executed in the first code cell. It sets the value of 'msg' to this string."

# %%
## Display the message
msg

# %%
150 + 150
vscode_nb_cells
Notebook cells in VSCode