5

I want to execute cells in an IPython / Jupyer notebook programmatically and do some introspection on them, like getting user variables.

With IPython.core.InteractiveShell it is quite easy:

from IPython.core.interactiveshell import InteractiveShell
shell = InteractiveShell()
shell.run_cell("foo = 1")
assert shell.ns_table['user_local']['foo'] == 1

I cannot user InteractiveShell though because I want to capture rich output (as discussed in another question). In order to do that, I have to use jupyter_client which uses a ZeroMQ connection to the kernel.

My question is, how can I retrieve object from the namespace of an IPython kernel, the way ns_table does in the above example? Is some kind of boilerplate code injection into cell source and/or pickling/unpickling of user expressions unavoidable (as discussed in yet another question)?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.