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