emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] org-babel -- Improper syntax error in session mode?


From: Herbert Sitz
Subject: Re: [O] org-babel -- Improper syntax error in session mode?
Date: Mon, 20 Jun 2011 20:45:05 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

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







reply via email to

[Prev in Thread] Current Thread [Next in Thread]