From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gary Oberbrunner Subject: Re: Fwd: Fwd: run python from org, draft Date: Sun, 31 Mar 2013 16:04:31 -0400 Message-ID: References: <5154BC51.1050001@easy-emacs.de> <5155A97D.2090907@easy-emacs.de> <87sj3e6y5n.fsf@gmail.com> <5155B346.3060708@easy-emacs.de> <5156007A.6030003@easy-emacs.de> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=047d7b67785a29f37a04d93e03e8 Return-path: Received: from eggs.gnu.org ([208.118.235.92]:43819) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMOUV-0007lU-IG for emacs-orgmode@gnu.org; Sun, 31 Mar 2013 16:04:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UMOUS-0004ig-JD for emacs-orgmode@gnu.org; Sun, 31 Mar 2013 16:04:35 -0400 Received: from mail-oa0-f41.google.com ([209.85.219.41]:61147) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMOUS-0004go-BU for emacs-orgmode@gnu.org; Sun, 31 Mar 2013 16:04:32 -0400 Received: by mail-oa0-f41.google.com with SMTP id f4so1519785oah.28 for ; Sun, 31 Mar 2013 13:04:31 -0700 (PDT) In-Reply-To: <5156007A.6030003@easy-emacs.de> 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: =?ISO-8859-1?Q?Andreas_R=F6hler?= Cc: Orgmode Mailing List , Eric Schulte --047d7b67785a29f37a04d93e03e8 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Fri, Mar 29, 2013 at 4:58 PM, Andreas R=F6hler < andreas.roehler@easy-emacs.de> wrote: > Am 29.03.2013 21:10, schrieb Gary Oberbrunner: > > 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 sessi= on >> mode is the last expression executed, and in non-session mode is whateve= r >> you return().) >> >> I agree it is a little odd, but given how python works it's not clear to >> me >> how to improve it. >> > > Hi Gary, > > if someone wants the value of the last expression returned, it's much > simpler to write Python/native > language, than cryptic, lately documented org-mode flags. > That's a kind of re-inventing a programming-language, also redundant. > > 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, >> > > No? Any program may output any of it's values. > > 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' a= t >> the shell. So using return() there doesn't make any sense, and wouldn't >> work. >> > > The use of "return" doesn't depend from interactive mode. > It's related to a function. > > Seen from org-user, IMO any back-ends interactive mode or not is not of > interest. > ":session" mimics and/or probably uses it, but it would also possible to > implement it as a file, loading > previous values from a storage. > > I don't see any way to make them both behave the same way. > > Probably most useful at this list is to define which feature/behavior is > most convenient. > Why people use this mode, what they want to do. > I think the very most useful thing would be for you to code up what you're thinking of, and show it here. --=20 Gary --047d7b67785a29f37a04d93e03e8 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable



On Fri, Mar 29, 2013 at 4:58 PM, Andreas R=F6hler <and= reas.roehler@easy-emacs.de> wrote:
Am 29.03.2013 21:10, schrieb Gary Oberbrunne= r:

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. =A0The default is :results value (which in sessio= n
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 t= o me
how to improve it.

Hi Gary,

if someone wants the value of the last expression returned, it's much s= impler to write Python/native
language, than cryptic, lately documented org-mode flags.
That's a kind of re-inventing a programming-language, also redundant.
=A0Specifically, in non-session mode, the python
interpreter is 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-interactive mode,

No? Any program may output any of it's values.

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. =A0Conversely in session mode, each block is talking to the same
interactive python interpreter, just what you get if you type 'python&#= 39; at
the shell. =A0So using return() there doesn't make any sense, and would= n't
work.

The use of "return" doesn't depend from interactive mode.
It's related to a function.

Seen from org-user, IMO any back-ends interactive mode or not is not of int= erest.
":session" mimics and/or probably uses it, but it would also poss= ible to implement it as a file, loading
previous values from a storage.

I don't see any way to make them both behave the same way.

Probably most useful at this list is to define which feature/behavior is mo= st convenient.
Why people use this mode, what they want to do.

I think the very most useful thing would be for you to code = up what you're thinking of, and show it here.
=A0
--
Gary
--047d7b67785a29f37a04d93e03e8--