Function: org-babel-python-evaluate-session
org-babel-python-evaluate-session is a byte-compiled function defined
in ob-python.el.gz.
Signature
(org-babel-python-evaluate-session SESSION BODY &optional RESULT-TYPE RESULT-PARAMS GRAPHICS-FILE)
Documentation
Pass BODY to the Python process in SESSION.
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. If GRAPHICS-FILE is
non-nil, then save graphical results to that file instead.
Source Code
;; Defined in /usr/src/emacs/lisp/org/ob-python.el.gz
(defun org-babel-python-evaluate-session
(session body &optional result-type result-params graphics-file)
"Pass BODY to the Python process in SESSION.
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. If GRAPHICS-FILE is
non-nil, then save graphical results to that file instead."
(let* ((tmp-src-file (org-babel-temp-file "python-"))
(results
(progn
(with-temp-file tmp-src-file
(insert (if (and graphics-file (eq result-type 'output))
(format org-babel-python--output-graphics-wrapper
body graphics-file)
body)))
(pcase result-type
(`output
(let ((body (format "\
with open('%s') as f:
exec(compile(f.read(), f.name, 'exec'))"
(org-babel-process-file-name
tmp-src-file 'noquote))))
(org-babel-python-send-string session body)))
(`value
(let* ((results-file (or graphics-file
(org-babel-temp-file "python-")))
(body (org-babel-python-format-session-value
tmp-src-file results-file result-params)))
(org-babel-python-send-string session body)
(sleep-for 0.010)
(org-babel-eval-read-file results-file)))))))
(org-babel-result-cond result-params
results
(org-babel-python-table-or-string results))))