From: John Kitchin <jkitchin@andrew.cmu.edu>
To: Nicolas Goaziou <mail@nicolasgoaziou.fr>
Cc: emacs-org <emacs-orgmode@gnu.org>, Florian Lindner <mailinglists@xgm.de>
Subject: Re: Problem with python session
Date: Mon, 10 Oct 2016 14:40:18 -0400 [thread overview]
Message-ID: <m2d1j86oa5.fsf@andrew.cmu.edu> (raw)
In-Reply-To: <87twclkgyr.fsf@nicolasgoaziou.fr>
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 "<stdin>", 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 "<stdin>", line 3
^
IndentationError: expected an indented block
File "<stdin>", line 1
pass
^
IndentationError: unexpected indent
>>> File "<stdin>", 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 <whenney@gmail.com> 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
next prev parent reply other threads:[~2016-10-10 18:40 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-06 12:41 Problem with python session Florian Lindner
2016-10-06 17:54 ` William Henney
2016-10-09 9:30 ` Nicolas Goaziou
2016-10-10 18:40 ` John Kitchin [this message]
2016-10-11 15:53 ` Nicolas Goaziou
2016-10-13 4:10 ` William Henney
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2d1j86oa5.fsf@andrew.cmu.edu \
--to=jkitchin@andrew.cmu.edu \
--cc=emacs-orgmode@gnu.org \
--cc=mail@nicolasgoaziou.fr \
--cc=mailinglists@xgm.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.