From: Herbert Sitz <hsitz@nwlink.com>
To: emacs-orgmode@gnu.org
Subject: Re: org-babel -- Improper syntax error in session mode?
Date: Mon, 20 Jun 2011 20:45:05 +0000 (UTC) [thread overview]
Message-ID: <loom.20110620T223952-132@post.gmane.org> (raw)
In-Reply-To: 87ei2ouwxk.fsf@gmail.com
Eric Schulte <schulte.eric <at> gmail.com> writes:
> I've changed the python session evaluation so that it explicitly sends a
> RET to the inferior Python process after every line of input. The
> attached patch makes this change.
> I can confirm that this fixes the
> problem in your example (when an empty line is placed between the block
> and the subsequent print statement)
Eric --
I did confirm that the patch works with this block:
------------------------------------------------
#+begin_src python :results output :session mypy
x = 1
for i in range(1,5):
x = x + i
print x
print "Did it work?"
#+end_src
------------------------------------------------
But it doesn't work with the block below, which _is_ valid Python code. I'm not
sure whether you're aware that it isn't working with the code below (and were
thinking that the code below is _not_ valid python), or whether you were going
to require the user to input blank lines at appropriate spots:
----------------------------------------------
#+begin_src python :results output :session mypy
x = 1
for i in range(1,5):
x = x + i
print x
print "Did it work?"
#+end_src
-------------------------------------------
The above block is valid Python, it's just because of the quirk of the
interactive python shell that it has to have a blank line inserted before the
[print "Did it work?"] line.
The locations where the blank lines would need to be inserted in code are
wherever the line indent goes from >0 back to 0. A user could be required to
insert these, of course, but since it's valid python to leave them out it seems
like something org-babel should do behind the scenes.
The '0 indent' for purposes of python execution is the smallest indent in the
org-babel source. So even though all source code lines are indented in above
org block, the line 'x=1' has zero indent for python eval purposes. The
relevance of this is just to show that extra lines for shell/babel evaluation
are necessary only when code indent goes back to zero, not when indent merely
becomes smaller. So the code below works fine, even though indent shrinks after
'print y' and 'print z' statements::
------------------------------
#+begin_src python :results output :session mypy
x = 1
y = 1
z = 1
for i in range(1,5):
x = x + i
print x
for y in range(10,15):
print y
for z in range(20,25):
print z
print "Did it work?"
#+end_src
------------------------------------
Like the simpler example, though, it doesn't work with with the blank line
omitted, which it should.
I hope I'm not confusing things. The patch does help, but doesn't address the
extra-line insertion issue.
-- Herb
next prev parent reply other threads:[~2011-06-20 20:45 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-19 21:54 org-babel -- Improper syntax error in session mode? Herbert Sitz
2011-06-19 23:21 ` Eric Schulte
2011-06-20 1:59 ` Herbert Sitz
2011-06-20 2:12 ` Herbert Sitz
2011-06-20 3:17 ` Nick Dokos
2011-06-20 3:46 ` Herbert Sitz
2011-06-20 19:23 ` Eric Schulte
2011-06-20 20:45 ` Herbert Sitz [this message]
2011-06-20 21:15 ` Eric Schulte
2011-06-20 23:16 ` Herbert Sitz
2011-06-21 0:08 ` Nick Dokos
2011-06-21 0:27 ` Herbert Sitz
[not found] ` <hesitz@gmail.com>
2011-06-21 1:17 ` Nick Dokos
2011-06-21 2:19 ` Eric Schulte
2011-06-21 5:13 ` Herbert Sitz
2011-06-21 7:15 ` Thomas S. Dye
2011-06-21 15:35 ` Herbert Sitz
2011-06-21 16:27 ` Thomas S. Dye
2011-06-21 17:42 ` Eric Schulte
2011-06-21 17:51 ` Herbert Sitz
2011-06-21 17:52 ` Eric Schulte
2011-06-27 18:09 ` Herbert Sitz
2011-06-21 17:26 ` Eric Schulte
2011-06-27 18:22 ` Herbert Sitz
2011-06-20 21:18 ` Jambunathan K
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
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=loom.20110620T223952-132@post.gmane.org \
--to=hsitz@nwlink.com \
--cc=emacs-orgmode@gnu.org \
/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 public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).