0

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 ?

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, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.