[Top][All Lists]

[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 03:46:41 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Nick Dokos <nicholas.dokos <at> hp.com> writes:
> Having said that, however, I think there *is* a problem:
> If you just start the python interpreter and start typing into it:
> --8<---------------cut here---------------start------------->8---
> x = 1
> for i in range(1,5):
>   x = x + i
>   print x
> print "Did it work?"
> --8<---------------cut here---------------end--------------->8---
> the problem becomes obvious: the interpreter is still in "indented mode"
> and complains about the last print, because it is not "properly"
> indented.  OTOH, if you exit "indented mode" by pressing another RET
> before the final print, the interpreter is happy. This is a kludge used
> by the interactive interpreter to accommodate python's reliance on
> indentation to delimit block structure.
> That however does not work with babel: even if I leave empty lines
> between the print x and the last print, the error persists. Apparently,
> babel does not send the empty lines to the interpreter. If there is a
> bug in babel, it seems to me this is it.
> Nick

Yep, that's what I was thinking.  Experiment a little I found that wrapping it
in a function gets around part of the problem.  This works fine in the terminal,
although it doesn't work from the equivalent Babel source block:
--8<---------------cut here---------------start------------->8---
>>> def myfunc():
...    x=1
...    for i in range(1,5):
...       x=x+i
...       print x
...    print "Did it work?"
>>> myfunc()
Did it work?
--8<---------------cut here---------------start------------->8---

I don't know whether having Babel feed things in pieces and assemble output is
complicated for the general case.  It seems to me it wouldn't be that bad, it's
only the lines where an indent reverts to zero indent where pieces would need to
be broken up.  As a partial solution, having Babel insert the requisite blank
line after the last line of a function def would be helpful, and I think the
output would then all end up in a single block, no need to reassemble (or maybe
output reassembly is just simplified a little).

-- Herb

reply via email to

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