From mboxrd@z Thu Jan 1 00:00:00 1970 From: Soapy Smith Subject: Re: Python Code Block error with header option :results output Date: Sat, 01 Feb 2014 07:34:57 -0500 Message-ID: <1391258097.11022.7.camel@raven-CM5571> References: <1391187052.2534.12.camel@raven-CM5571> <1391203457.2534.18.camel@raven-CM5571> <87zjmbu98e.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:41063) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W9ZnM-0003TM-C8 for emacs-orgmode@gnu.org; Sat, 01 Feb 2014 07:35:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W9ZnF-0003kt-4w for emacs-orgmode@gnu.org; Sat, 01 Feb 2014 07:35:36 -0500 Received: from qmta15.westchester.pa.mail.comcast.net ([76.96.59.228]:52693) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W9ZnE-0003ko-Sz for emacs-orgmode@gnu.org; Sat, 01 Feb 2014 07:35:29 -0500 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: Christian Moe Cc: emacs-orgmode@gnu.org, Eric Schulte On Sat, 2014-02-01 at 07:56 +0100, Christian Moe wrote: > > You should only use "return" like that in a python code block when you > > have ":results value". > > To expand briefly on that (since this can be perplexing): > > The need to use `return' at all when returning the value is a special > quirk of Python code blocks, and does not apply to (any?) other languages. > > As explained on Worg, with `:results value' (the default), > > "Internally, the value is obtained by wrapping the code in a function > definition in the external language, and evaluating that > function. Therefore, code should be written as if it were the body of > such a function. In particular, note that Python does not automatically > return a value from a function unless a return statement is present, and > so a ‘return’ statement will usually be required in Python." > > http://orgmode.org/manual/Results-of-evaluation.html > > So when using `:results output', using `return' causes an error > because there is no function to return anything from. > > Yours, > Christian Thank you Christian for the detailed explanation. It is indeed perplexing at first! Regards, Greg