AFAIU it's caused by a call to org-trim. The followingUpdated patch fixes it here:
--- ../../../emacs-20190711/lisp/org/ob-python.el 2019-07-09 16:46:01.274976504 +0200 +++ ob-python.el 2019-08-08 2021:2251:11.668166099185799006 +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 +322+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 +345+347,710 @@ (insert org-babel-python-eoe-indicator) (funcall send-wait))) (org-babel-eval-read-file tmp-file)))))) + (when (listp results) + (setqdolist (ele results) + (carsetq erg (concat erg (ignore-safeerrors results(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