From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jack Kamm Subject: ob-python newline & indentation behavior Date: Sat, 18 Nov 2017 12:02:24 +0000 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:54990) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eG1x0-0005KY-9a for emacs-orgmode@gnu.org; Sat, 18 Nov 2017 07:10:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eG1wv-0008NO-VX for emacs-orgmode@gnu.org; Sat, 18 Nov 2017 07:10:22 -0500 Received: from [195.159.176.226] (port=48990 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eG1wv-0008Jc-Fp for emacs-orgmode@gnu.org; Sat, 18 Nov 2017 07:10:17 -0500 Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1eG1wj-0004fl-Ay for emacs-orgmode@gnu.org; Sat, 18 Nov 2017 13:10:05 +0100 Content-Language: en-US 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: emacs-orgmode@gnu.org ob-python newline & indentation behavior in :session is very ugly and possibly broken. For example, consider the following code block: #+BEGIN_SRC python :session :results output foo = 0 for _ in range(10): foo += 1 foo += 1 print(foo) #+END_SRC Ideally this would print "20", but instead it prints "11", because the second "foo+=1" is executed after the for loop. OTOH "python-shell-send-region" (from python.el) gives the correct answer of "20". The inconsistent behavior of "python-shell-send-region" and "org-babel-eval" often causes me problems, because I want to use both (the former for testing and async eval; the latter for inserting into the document). There is a 2 year old patch that fixes this behavior but has not yet been incorporated: https://lists.gnu.org/archive/html/emacs-orgmode/2015-03/msg00505.html The patch follows the python.el behavior of using a temporary file and executing that from the shell. Could this patch, or something similar, be incorporated into org-mode, to fix this behavior? Thanks, Jack Kamm