From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: Re: Problem with python session Date: Mon, 10 Oct 2016 14:40:18 -0400 Message-ID: References: <87twclkgyr.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:60700) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btfUx-000805-OS for emacs-orgmode@gnu.org; Mon, 10 Oct 2016 14:40:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1btfUt-0004wP-Ia for emacs-orgmode@gnu.org; Mon, 10 Oct 2016 14:40:26 -0400 Received: from mail-qk0-x236.google.com ([2607:f8b0:400d:c09::236]:35137) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btfUt-0004wE-D0 for emacs-orgmode@gnu.org; Mon, 10 Oct 2016 14:40:23 -0400 Received: by mail-qk0-x236.google.com with SMTP id z190so113749771qkc.2 for ; Mon, 10 Oct 2016 11:40:23 -0700 (PDT) In-reply-to: <87twclkgyr.fsf@nicolasgoaziou.fr> 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: Nicolas Goaziou Cc: emacs-org , Florian Lindner I am not sure it makes sense to change anything for this. There is different behavior with scripts and the interpreter independently of org-mode, e.g. with python -i: >>> for i in range(3): ... print(i) ... i File "", line 3 i ^ SyntaxError: invalid syntax Vanilla python sessions are kind of maddening. These seemingly identical blocks are different, i.e. one works and one doesn't! Spoiler alert, they are not identical. #+BEGIN_SRC python :results output org drawer :session for i in range(3): for j in range(3): pass print(i) #+END_SRC #+RESULTS: :RESULTS: ... File "", line 3 ^ IndentationError: expected an indented block File "", line 1 pass ^ IndentationError: unexpected indent >>> File "", line 1 print(i) ^ IndentationError: unexpected indent :END: This block which works has one space at the beginning of the blank lines. #+BEGIN_SRC python :results output org drawer :session for i in range(3): for j in range(3): pass print(i) #+END_SRC #+RESULTS: :RESULTS: ... ... ... ... ... 0 1 2 :END: This kind of error would be hard to reliably fix IMHO since it would rely on replacing blank lines with at least a space, and adding a blank line after indentation changes, except they can not be empty, they need at least a space in them. It is not clear that is a good idea. Maybe a test that replaces "\n" with "\n \n" might clear it up, but might also add a bunch of the ... >>> characters in the output? This is not an issue with python scripts or ipython, however. Nicolas Goaziou writes: > Hello, > > William Henney writes: > >> I can reproduce your problem. This is (arguably) a bug in ob-python when >> using the vanilla python interpreter together with the :session argument. >> You can work around it by putting a blank line after the for-loop in your >> second code block. >> >> I say that it is arguable that this is a bug or not since you would have >> exactly the same error if you were to literally type your code block in at >> the python interactive prompt. That is, you have to give a second newline >> in order to close the loop and return to the top-level prompt. However, it >> is admittedly confusing to have different behavior with and without the >> ":session" argument. > > Thank you for the analysis. Would you have a suggestion on how to > improve the situation? > > Regards, -- Professor John Kitchin Doherty Hall A207F Department of Chemical Engineering Carnegie Mellon University Pittsburgh, PA 15213 412-268-7803 @johnkitchin http://kitchingroup.cheme.cmu.edu