From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kyle Meyer Subject: Re: ob-python newline & indentation behavior Date: Mon, 20 Nov 2017 23:04:31 -0500 Message-ID: <87r2ssp99s.fsf@kyleam.com> References: <87h8trtyoa.fsf@kyleam.com> <8760a5tqjo.fsf@kyleam.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:51299) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eGznh-0008SL-BF for emacs-orgmode@gnu.org; Mon, 20 Nov 2017 23:04:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eGzne-00022m-7a for emacs-orgmode@gnu.org; Mon, 20 Nov 2017 23:04:45 -0500 Received: from pb-smtp1.pobox.com ([64.147.108.70]:60756 helo=sasl.smtp.pobox.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eGzne-00022D-1W for emacs-orgmode@gnu.org; Mon, 20 Nov 2017 23:04:42 -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" To: Jack Kamm Cc: emacs-orgmode@gnu.org Jack Kamm writes: > In response to this: > >> I can't think of a good solution, though. Stepping back a bit, I think >> it's unfortunate that python blocks handle ":results value" differently >> depending on whether the block is hooked up to a session or not. For >> non-sessions, you have to use return. Using the same approach >> (org-babel-python-wrapper-method) for ":session :results value", we >> could then get the return value reliably, but the problem with this >> approach is that any variables defined in a ":results value" block >> wouldn't be defined in the session after executing the block because the >> code is wrapped in a function. > > How about if we used the "globals()" and "locals()" functions in Python? > > Something like this at the end of the wrapper block, before return: > > for k, v in locals().items(): > globals()[k] = v Hmm, placing that code "before return" is a problem. Like with non-session ":results value" blocks, the user would be responsible for inserting the return (or even multiple return's), so we can't know where to insert the above code without parsing the block :/ > Another bug with the current approach is that it breaks if common idioms > like "for _ in range(10)" are used. ("_" is used to inspect the last output > of the shell, an obscure feature I hadn't known about until now). Right. Also, IIRC the built-in interactive python and ipython treat multiline blocks differently. With if True: "ipython ignores my existence" the built-in shell binds "_" to the string's value, but ipython doesn't. -- Kyle