From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rustom Mody Subject: babel - python question Date: Fri, 5 Jul 2013 18:14:28 +0530 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a11c2d15a6ba86204e0c30fa9 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:44336) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uv5Nb-0004IO-Gt for emacs-orgmode@gnu.org; Fri, 05 Jul 2013 08:44:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uv5Na-0006Qy-0z for emacs-orgmode@gnu.org; Fri, 05 Jul 2013 08:44:51 -0400 Received: from mail-ie0-x232.google.com ([2607:f8b0:4001:c03::232]:52066) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uv5NZ-0006Qr-SF for emacs-orgmode@gnu.org; Fri, 05 Jul 2013 08:44:49 -0400 Received: by mail-ie0-f178.google.com with SMTP id u16so5232353iet.37 for ; Fri, 05 Jul 2013 05:44:48 -0700 (PDT) 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: emacs-orgmode --001a11c2d15a6ba86204e0c30fa9 Content-Type: text/plain; charset=ISO-8859-1 [Complete babel noob here] Following the babel doc http://orgmode.org/worg/org-contrib/babel/intro.html#library-of-babel I wrote this * Head #+name: ppp :results value #+begin_src python import time print("Hello, today's date is %s" % time.ctime()) print('Two plus two is') return 2 + 2 #+end_src Hit C-c C-c and got a new block #+RESULTS: : 4 I am mystified! In python a top level return gives a syntax error. Here it works. Is some secret function being created? Also the results changed to output does not change the behavior --001a11c2d15a6ba86204e0c30fa9 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable [Complete babel noob here]

Following the babel doc http://orgmode.org/worg/org-contrib/babel/intro.html#library-of-bab= el

I wrote this

* Head
#+name: ppp :results value
#+begin_src python
import ti= me
print("Hello, today's date is %s" % time.ctime())
pr= int('Two plus two is')
return 2 + 2
#+end_src

Hit C-c = C-c

and got a new block

#+RESULTS:
: 4


I am mystified!=
In python a top level return gives a syntax error.
Here it works. Is= some secret function being created?

Also the results changed to out= put does not change the behavior
--001a11c2d15a6ba86204e0c30fa9-- From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: babel - python question Date: Fri, 05 Jul 2013 08:28:23 -0600 Message-ID: <87vc4pgjy0.fsf@gmail.com> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:49050) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uv71R-00082p-8r for emacs-orgmode@gnu.org; Fri, 05 Jul 2013 10:30:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uv71P-0002mA-0q for emacs-orgmode@gnu.org; Fri, 05 Jul 2013 10:30:05 -0400 Received: from mail-pd0-x236.google.com ([2607:f8b0:400e:c02::236]:35641) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uv71O-0002iz-Pc for emacs-orgmode@gnu.org; Fri, 05 Jul 2013 10:30:02 -0400 Received: by mail-pd0-f182.google.com with SMTP id r10so2071904pdi.27 for ; Fri, 05 Jul 2013 07:30:02 -0700 (PDT) In-Reply-To: (Rustom Mody's message of "Fri, 5 Jul 2013 18:14:28 +0530") 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: Rustom Mody Cc: emacs-orgmode Rustom Mody writes: > [Complete babel noob here] > > Following the babel doc > http://orgmode.org/worg/org-contrib/babel/intro.html#library-of-babel > > I wrote this > > * Head > #+name: ppp :results value > #+begin_src python > import time > print("Hello, today's date is %s" % time.ctime()) > print('Two plus two is') > return 2 + 2 > #+end_src > > Hit C-c C-c > > and got a new block > > #+RESULTS: > : 4 > > > I am mystified! > In python a top level return gives a syntax error. > Here it works. Is some secret function being created? > Yes, when returning a value, the code block itself becomes a function. > > Also the results changed to output does not change the behavior Not true, however you need to put the header arguments on the begin_src line or on a #+headers line (not on the #+name line). Also, try to mix :results output and "return 2 + 2", and you should find the error you expected earlier. Best, #+begin_src python :results value import time print("Hello, today's date is %s" % time.ctime()) print('Two plus two is') return 2 + 2 #+end_src #+RESULTS: : 4 #+begin_src python :results output import time print("Hello, today's date is %s" % time.ctime()) print('Two plus two is') #+end_src #+RESULTS: : Hello, today's date is Fri Jul 5 08:27:02 2013 : Two plus two is -- Eric Schulte http://cs.unm.edu/~eschulte