First, let me mention that when Jupyter notebooks are running only IPython kernels, they still are IPython notebooks. ;)
If you would like automatic source code formatting in Jupyter notebooks, follow these instructions.
I'm using the black Python formatter for this and the pip package nb_black from Khoa Duong to achieve this.
First, install nb_black
which will automatically pull in the black
formatting package:
pip install nb_black
Now your first cell in a Jupyter notebook should be:
%load_ext nb_black
or, in a jupyterlab
notebook:
%load_ext lab_black
.
If there's ever a problem with the source code formatting, simply don't execute the first cell while running the notebook.
In [ ]: