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)

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.

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)
  "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."
  (let* ((tmp-src-file (org-babel-temp-file "python-"))
         (results
	  (progn
	    (with-temp-file tmp-src-file (insert body))
            (pcase result-type
	      (`output
	       (let ((body (format org-babel-python--exec-tmpfile
				   (org-babel-process-file-name
				    tmp-src-file 'noquote))))
		 (org-babel-python--send-string session body)))
              (`value
               (let* ((tmp-results-file (org-babel-temp-file "python-"))
		      (body (org-babel-python-format-session-value
			     tmp-src-file tmp-results-file result-params)))
		 (org-babel-python--send-string session body)
		 (sleep-for 0 10)
		 (org-babel-eval-read-file tmp-results-file)))))))
    (org-babel-result-cond result-params
      results
      (org-babel-python-table-or-string results))))