This is the official manual for the latest Org-mode release.
The way in which results are handled depends on whether a session is invoked,
as well as on whether
:results value or
:results output is
used. The following table shows the table possibilities. For a full listing
of the possible results header arguments see results.
|value of last expression||value of last expression
|contents of STDOUT||concatenation of interpreter output
:results value, the result in both
non-session is returned to Org mode as a table (a one- or two-dimensional
vector of strings or numbers) when appropriate.
This is the default. Internally, the value is obtained by wrapping the code
in a function definition in the external language, and evaluating that
function. Therefore, code should be written as if it were the body of such a
function. In particular, note that Python does not automatically return a
value from a function unless a
return statement is present, and so a
‘return’ statement will usually be required in Python.
This is the only one of the four evaluation contexts in which the code is automatically wrapped in a function definition.
The code is passed to the interpreter as an external process, and the contents of the standard output stream are returned as text. (In certain languages this also contains the error output stream; this is an area for future work.)
The code is passed to an interpreter running as an interactive Emacs inferior
process. Only languages which provide tools for interactive evaluation of
code have session support, so some language (e.g., C and ditaa) do not
:session header argument, and in other languages (e.g.,
Python and Haskell) which have limitations on the code which may be entered
into interactive sessions, those limitations apply to the code in code blocks
:session header argument as well.
:results output option is supplied (see below) the result
returned is the result of the last evaluation performed by the
interpreter. (This is obtained in a language-specific manner: the value of
_ in Python and Ruby, and the value of
The code is passed to the interpreter running as an interactive Emacs
inferior process. The result returned is the concatenation of the sequence of
(text) output from the interactive interpreter. Notice that this is not
necessarily the same as what would be sent to
STDOUT if the same code
were passed to a non-interactive interpreter running as an external
process. For example, compare the following two blocks:
#+BEGIN_SRC python :results output print "hello" 2 print "bye" #+END_SRC #+RESULTS: : hello : bye
In non-session mode, the `2' is not printed and does not appear.
#+BEGIN_SRC python :results output :session print "hello" 2 print "bye" #+END_SRC #+RESULTS: : hello : 2 : bye
:session mode, the interactive interpreter receives input `2'
and prints out its value, `2'. (Indeed, the other print statements are