ob-python newline & indentation behavior in :session is very ugly and possibly broken. For example, consider the following code block:

#+BEGIN_SRC python :session :results output
  foo = 0
  for _ in range(10):
      foo += 1

      foo += 1

  print(foo)
#+END_SRC

Ideally this would print "20", but instead it prints "11",
because the second "foo+=1" is executed after the for loop.
OTOH "python-shell-send-region" (from python.el) gives the correct answer of "20".

The inconsistent behavior of "python-shell-send-region" and "org-babel-eval" often causes me problems, because I want to use both (the former for testing and async eval; the latter for inserting into the document).

There is a 2 year old patch that fixes this behavior but has not yet been incorporated:
https://lists.gnu.org/archive/html/emacs-orgmode/2015-03/msg00505.html

The patch follows the python.el behavior of using a temporary file and executing that from the shell.

Could this patch, or something similar, be incorporated into org-mode, to fix this behavior?

Thanks,
Jack Kamm


Reply via email to