1

If I run the following code block:

#+BEGIN_SRC python :results output

  print("   /|")
  print("  / |")
  print(" /  |")
  print("/___|")

#+END_SRC

I get the result as expected:

#+RESULTS:
:    /|
:   / |
:  /  |
: /___|

But if I now run this as part of a session, the result breaks:

#+BEGIN_SRC python :session *Python* :results output

  print("   /|")
  print("  / |")
  print(" /  |")
  print("/___|")

#+END_SRC

#+RESULTS:
: /|
:   / |
:  /  |
: /___|

This is what I have in init.el:

;; Babel languages
(org-babel-do-load-languages
 'org-babel-load-languages
 '((emacs-lisp . t)
   (R . t)
   (latex . t)
   (shell . t)
   (php . t)
   (applescript . t)
   (python . t)))

;; Fix Warning "readline" message
(setq python-shell-completion-native-enable nil)

Any ideas?

0

AFAIU it's caused by a call to org-trim. Updated patch:

--- ../../../emacs-20190711/lisp/org/ob-python.el   2019-07-09 16:46:01.274976504 +0200
+++ ob-python.el    2019-08-08 21:51:11.185799006 +0200
@@ -294,7 +294,9 @@
 If RESULT-TYPE equals `output' then return standard output as a
 string.  If RESULT-TYPE equals `value' then return the value of the
 last statement in BODY, as elisp."
-  (let* ((send-wait (lambda () (comint-send-input nil t) (sleep-for 0 5)))
+  (let* ((erg "")
+         (filter-re (concat python-shell-prompt-regexp "\\|" "'org_babel_python_eoe'\n" "\\|" "#.+"))
+         (send-wait (lambda () (comint-send-input nil t) (sleep-for 0 5)))
     (dump-last-value
      (lambda
        (tmp-file pp)
@@ -322,16 +324,17 @@
                   (format org-babel-python--exec-tmpfile
                       tmp-src-file))
               body)))
-          (mapconcat
-       #'org-trim
-       (butlast
+          ;; (mapconcat
+               ;; #'org-trim
+               ;; (butlast
         (org-babel-comint-with-output
             (session org-babel-python-eoe-indicator t body)
           (funcall input-body body)
           (funcall send-wait) (funcall send-wait)
           (insert org-babel-python-eoe-indicator)
           (funcall send-wait))
-        2) "\n")))
+               ;; 2) "\n")
+               ))
             (`value
              (let ((tmp-file (org-babel-temp-file "python-")))
                (org-babel-comint-with-output
@@ -344,6 +347,10 @@
                    (insert org-babel-python-eoe-indicator)
                    (funcall send-wait)))
                (org-babel-eval-read-file tmp-file))))))
+    (when (listp results)
+      (dolist (ele results)
+        (setq erg (concat erg (ignore-errors (replace-regexp-in-string  filter-re "" ele))))))
+    (setq results erg)
     (unless (string= (substring org-babel-python-eoe-indicator 1 -1) results)
       (org-babel-result-cond result-params
    results

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.