Skip to content

Instantly share code, notes, and snippets.

@CatChenal
Last active July 4, 2022 19:53
Show Gist options
  • Save CatChenal/c9187015b9d695b6ef3ea6105604d0ed to your computer and use it in GitHub Desktop.
Save CatChenal/c9187015b9d695b6ef3ea6105604d0ed to your computer and use it in GitHub Desktop.
Code included in the first cell of a Jupyter notebook to allow multi-output

Code that I ususally include in the first cell of a jupyter nootebook:

from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
  • This avoids using print() to obtain multiple outputs in one cell. For example, given this code in one cell:
a = 1
b = 2
a
b

The output will be*:

1 
2 

[*] Except in Google's colab: the new line character is stripped so the out put is 1 2.

I also add the following line if autocomplete or introspection is taking too long:

%config Completer.use_jedi = False

See this SO answer for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment