View on GitHub

PythonTipsAndTricks

PTT

Jupyter

Jupyter notebook clear cell output in code

See https://stackoverflow.com/a/24818304/2268280

from IPython.display import clear_output

for i in range(10):
    clear_output(wait=True)
    print("Hello World!")

Save jupyter notebook command

%%javascript
IPython.notebook.save_notebook()

Important extensions

Widgets

pip install ipywidgets jupyterlab_widgets

Example

radiobutton = widgets.RadioButtons(
    options=[True, False],
    value=False, # Defaults to 'pineapple'
#    layout={'width': 'max-content'}, # If the items' names are long
    description='New letter?',
    disabled=False
)
output_radiobutton = widgets.Output()

which can be used inside a jupyter notebook as:

radiobutton.description = "Load Body?"
radiobutton.value = True
display(radiobutton,output_radiobutton)

image Once selected, store with `LOAD_BODY = radiobutton.get_interact_value()

MyST

pip install jupyterlab_myst

Example

```{figure} https://source.unsplash.com/random/500x200/?mountain :label: my-fig :align: center

My bold mountain 🏔🚠. ```

Check out !!