emacs-jupyter / jupyter

An interface to communicate with Jupyter kernels.
GNU General Public License v3.0
944 stars 93 forks source link

Multiple results mode? #386

Open indigoviolet opened 2 years ago

indigoviolet commented 2 years ago

Thanks for your work on this package.

Is it possible to capture results from each statement/line in the source block? For instance, the below returns : world currently, but can it be made to return

: hello
: world

?

:PROPERTIES:
:header-args: :session test :kernel python :results raw drawer replace
:END:

#+begin_src jupyter-python
"hello"
"world"
#+end_src

#+RESULTS:
: world

The IPython equivalent is

from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
nchisholm commented 2 years ago

If you don't mind calling display on each line you want shown, you get the desired result.

#+begin_src jupyter-python
display("hello")
display("world")
#+end_src

#+RESULTS:
:RESULTS:
: hello
: world
:END:
indigoviolet commented 2 years ago

Thanks!

I think this (multiple results without display()) would be a useful feature to have; in my experience I use that IPython snippet in every notebook, and it is nice not to have to remember to wrap everything in display().

nchisholm commented 2 years ago

Oh, I see - sorry if I stated the obvious then. It took me some time to figure out that you could call display a bunch of times to get multiple outputs. In the Jupyter notebook it is ergonomic to have each statement on a separate cell, but not as much form within org mode due to the boilerplate. Could be nice to have something like :results verbose to get an output for each line.