1

So apparently org-babel is evaluating python code inside its own function, perhaps when calling the interpreter or to be able to return the #+RESULTS: I guess. How to instruct it to evaluate the same way that the python mode does (say C-c ' and C-c C-c) ?

Example :

#+Begin_src python
from math import *
#+end_src

Evaluating to python3 directly from org spits in Org-Babel Error Output :

  File "<stdin>", line 2 
SyntaxError: import * only allowed at module level 

Python 2.7 being more permissive, illustrating the situation called for a different example

#+Begin_src python 
from Tkinter import *

class MainWindow():
   def __init__(self,parent):
        # the following line stumbles on the problem
        Frame(self , parent)            
        pass

Tk()
#+end_src

I'm pretty sure there's an option to bypass the case. What could it be ?

3
  • 1
    try using #+Begin_src python :session Commented Sep 29, 2016 at 2:52
  • Thanks. Found the answer while finishing to read the babel docs and redacting the post in the meantime... orgmode.org/worg/org-contrib/babel/… Commented Sep 29, 2016 at 3:20
  • 1
    you can answer your own question, if you found out the answer Commented Sep 29, 2016 at 9:35

1 Answer 1

1

As stated in the babel introduction : Setting the system wide header argument :session

run an interactive session as an "inferior process" within Emacs. This means that an environment is created containing data objects that persist between different source code blocks.

Also, in non-session mode, the python code block will be wrapped in a function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.