From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gary Oberbrunner Subject: Fwd: Fwd: run python from org, draft Date: Fri, 29 Mar 2013 16:10:53 -0400 Message-ID: References: <5154BC51.1050001@easy-emacs.de> <5155A97D.2090907@easy-emacs.de> <87sj3e6y5n.fsf@gmail.com> <5155B346.3060708@easy-emacs.de> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=047d7b67319845e08704d915de3c Return-path: Received: from eggs.gnu.org ([208.118.235.92]:50611) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ULfdY-0005AC-RM for emacs-orgmode@gnu.org; Fri, 29 Mar 2013 16:11:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ULfdW-0007bs-EH for emacs-orgmode@gnu.org; Fri, 29 Mar 2013 16:10:56 -0400 Received: from mail-pb0-f53.google.com ([209.85.160.53]:62919) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ULfdW-0007bk-7X for emacs-orgmode@gnu.org; Fri, 29 Mar 2013 16:10:54 -0400 Received: by mail-pb0-f53.google.com with SMTP id un1so384088pbc.26 for ; Fri, 29 Mar 2013 13:10:53 -0700 (PDT) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Orgmode Mailing List --047d7b67319845e08704d915de3c Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Fri, Mar 29, 2013 at 11:29 AM, Andreas R=F6hler < andreas.roehler@easy-emacs.de> 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. --=20 Gary --047d7b67319845e08704d915de3c Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

On Fri, Mar 2= 9, 2013 at 11:29 AM, Andreas R=F6hler <andreas.roehler@easy-em= acs.de> wrote:
IMO org-babel should be able to run sou= rce code as is.
If an org-mode specific modification is required at such a trivial form, wh= at 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. =A0The def= ault is :results value (which in session mode is the last expression execut= ed, 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. =A0Specifically, in non-session mode, the python interpreter i= s run as a separate process and fed the input (with some stuff around it). = =A0There is no way for python to get "the last value" in non-inte= ractive mode, so instead ob-python wraps your code in a function, then call= s it, and writes the return value of that function to the temp file. =A0Con= versely in session mode, each block is talking to the same interactive pyth= on interpreter, just what you get if you type 'python' at the shell= . =A0So using return() there doesn't make any sense, and wouldn't w= ork. =A0I don't see any way to make them both behave the same way.

--
Gary
--047d7b67319845e08704d915de3c--