4

I'm trying to write up a code test case using org-mode and babel but can't get past the first step:

* Running code example

Set up some variables
#+begin_src python :results output :session
x=1
#+end_src


Use some variables (in the end I'll have more useful
explanatory text between the code blocks).
#+begin_src python :exports both :results output :session 
print "Hi", x
#+end_src

Hitting C-c on the blocks in sequence fails since the second block doesn't have x defined.

Exporting the file (to PDF if that matters) seems to execute all of the code blocks, but the RESULTS of the second block are not constructed and inserted into the buffer.

How can I modify the switches on the code-blocks so that everything is executed in a session, and the results are embedded in the org buffer?

org-version=7.9.3f

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
Dave
  • 7,555
  • 8
  • 46
  • 88
  • I don't have Python, so I cannot try. But I don't see some obvious reason why it wouldn't work, as long as it's run in a session. Don't you have to add a name after the session parameter, maybe? – fniessen Jun 05 '14 at 13:47
  • Tried with a session name added -- same problem. – Dave Jun 05 '14 at 13:51
  • For me, with org-mode v8.2.10 it works as expected. – Dror Apr 24 '15 at 08:28

2 Answers2

5

Give the session a name, for example:

    #+name: session_init
    #+BEGIN_SRC python :results output :session example
    str='Hello, World'
    #+END_SRC

    #+RESULTS: session_init
    : 
    : str='Hello World'
    : >>> >>> >>>
    : 

    #+BEGIN_SRC python :results output :session example
    print str
    #+END_SRC

    #+RESULTS:
    : print str
    : Hello, World
    : 
alls0rts
  • 248
  • 3
  • 9
0

It works with a newer org-mode (e.g. 8.2.10); there are major changes from org 8.0 so the best way is to upgrade your org-mode.

TNT
  • 2,431
  • 1
  • 19
  • 26