Skip to main content
1 of 3
Aaron Hall
  • 434
  • 1
  • 6
  • 21

In a code block with :results output it takes the output from standard out, that is, what you print, as the results. This is what you were doing:

#+BEGIN_SRC python :session :results output import sys print(sys.version) #+END_SRC #+RESULTS: : 3.6.4 |Anaconda custom (64-bit)| (default, Mar 13 2018, 01:15:57) : [GCC 7.2.0] 

If you don't print (or write to standard out) with output, you get nothing:

#+BEGIN_SRC python :session :results output import sys sys.version #+END_SRC #+RESULTS: 

Orgmode will show the last value when you use session, when you use the :results value (which you can actually leave out because it is the default argument.):

#+BEGIN_SRC python :session :results value import sys sys.version #+END_SRC #+RESULTS: : 3.6.4 |Anaconda custom (64-bit)| (default, Mar 13 2018, 01:15:57) : [GCC 7.2.0] 

Or you can specify suboptions for value:

#+BEGIN_SRC python :session :results value raw import sys sys.version #+END_SRC #+RESULTS: 3.6.4 |Anaconda custom (64-bit)| (default, Mar 13 2018, 01:15:57) [GCC 7.2.0] 

So if you remove the argument, you get what you were actually expecting (since print() returns None):

#+BEGIN_SRC python :session 4-2 print(4+5) #+END_SRC #+RESULTS: : 2 

From orgmode's docs

:results {output, value}: Value mode is the default (as with other languages). In value mode you can use the following subtypes:

  • raw: value is inserted directly
  • pp: value is pretty-printed by python using pprint.pformat(%s), then inserted
  • file: value is interpreted as a filename to be interpolated when exporting; commonly used for graphics output.
Aaron Hall
  • 434
  • 1
  • 6
  • 21