Issue
To display multiple outputs in a cell I use,
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
But what if for I have a cell that I only want a single output from, how would I switch back in the same notebook.
I tried issuing
InteractiveShell.ast_node_interactivity = "last_expr"
in the cell where I wanted a single output from but it didn't seem to work.
Solution
You can issue the following in an IPython (terminal, notebook, ...) prompt:
%config
It will tell you which object can be configured:
Available objects for config:
AliasManager
DisplayFormatter
HistoryManager
IPCompleter
IPKernelApp
InlineBackend
LoggingMagics
MagicsManager
PrefilterManager
ScriptMagics
StoreMagics
ZMQInteractiveShell
Note that ZMQInteractiveShell
will be TerminalInteractiveShell
in a terminal. In our case that is, what we are interested in configuring, let's ask config
for more info:
%config ZMQInteractiveShell
ZMQInteractiveShell options
-------------------------
ZMQInteractiveShell.ast_node_interactivity=<Enum>
Current: 'last_expr'
Choices: ['all', 'last', 'last_expr', 'none', 'last_expr_or_assign']
'all', 'last', 'last_expr' or 'none', 'last_expr_or_assign' specifying which
nodes should be run interactively (displaying output from expressions).
ZMQInteractiveShell.ast_transformers=<List>
Current: []
Oh ! Well then let's assign that:
%config InteractiveShell.ast_node_interactivity="last_expr"
And you are set to go, and moreover you've learn how to dive into the IPython configuration system.
Note that it may not work for all config options (if so open a bug report) but it should for last_node_interactivity
, and the parser is a bit picky, you may need to not have spaces around the =
.
Enjoy !
Answered By - Matt
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.