emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] Fwd: Fwd: run python from org, draft


From: Gary Oberbrunner
Subject: [O] Fwd: Fwd: run python from org, draft
Date: Fri, 29 Mar 2013 16:10:53 -0400


On Fri, Mar 29, 2013 at 11:29 AM, Andreas Röhler <address@hidden> wrote:
IMO org-babel should be able to run source code as is.
If an org-mode specific modification is required at such a trivial form, what to expect wrt complex environments?

BTW this fails also:

#+begin_src python
print "Hello, world!"
#+end_src python

#+RESULTS:
: None

As the worg doc says, if you want to capture stdout rather than a value, you need :results output.  The default is :results value (which in session mode is the last _expression_ executed, and in non-session mode is whatever you return().)

I agree it is a little odd, but given how python works it's not clear to me how to improve it.  Specifically, in non-session mode, the python interpreter is run as a separate process and fed the input (with some stuff around it).  There is no way for python to get "the last value" in non-interactive mode, so instead ob-python wraps your code in a function, then calls it, and writes the return value of that function to the temp file.  Conversely in session mode, each block is talking to the same interactive python interpreter, just what you get if you type 'python' at the shell.  So using return() there doesn't make any sense, and wouldn't work.  I don't see any way to make them both behave the same way.

--
Gary

reply via email to

[Prev in Thread] Current Thread [Next in Thread]