Dave
Dave

Reputation: 8090

Org-mode babel python session does not produce results

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

Upvotes: 4

Views: 2220

Answers (2)

TNT
TNT

Reputation: 2511

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.

Upvotes: 0

alls0rts
alls0rts

Reputation: 258

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
    : 

Upvotes: 5

Related Questions