ob-python: in the case of ":results output table" results can be parsed as a table

* lisp/ob-python.el (org-babel-python-evaluate-external-process):
  Allow parsing as a table in the case of ":results output table".
  (org-babel-python-evaluate-session):   Allow parsing as a table in
  the case of ":results output table".
This commit is contained in:
Eric Schulte 2011-04-14 20:24:10 -06:00
parent b99ab9250b
commit 28b325fa1e
1 changed files with 46 additions and 39 deletions

View File

@ -202,29 +202,33 @@ open('%s', 'w').write( pprint.pformat(main()) )")
If RESULT-TYPE equals 'output then return standard output as a If RESULT-TYPE equals 'output then return standard output as a
string. If RESULT-TYPE equals 'value then return the value of the string. If RESULT-TYPE equals 'value then return the value of the
last statement in BODY, as elisp." last statement in BODY, as elisp."
(case result-type ((lambda (raw)
(output (org-babel-eval org-babel-python-command (if (or (member "code" result-params)
(concat (if preamble (concat preamble "\n") "") body))) (member "pp" result-params)
(value (let ((tmp-file (org-babel-temp-file "python-"))) (and (member "output" result-params)
(org-babel-eval org-babel-python-command (not (member "table" result-params))))
(concat raw
(if preamble (concat preamble "\n") "") (org-babel-python-table-or-string (org-babel-trim raw))))
(format (case result-type
(if (member "pp" result-params) (output (org-babel-eval org-babel-python-command
org-babel-python-pp-wrapper-method (concat (if preamble (concat preamble "\n") "")
org-babel-python-wrapper-method) body)))
(mapconcat (value (let ((tmp-file (org-babel-temp-file "python-")))
(lambda (line) (format "\t%s" line)) (org-babel-eval
(split-string org-babel-python-command
(org-remove-indentation (concat
(org-babel-trim body)) (if preamble (concat preamble "\n") "")
"[\r\n]") "\n") (format
(org-babel-process-file-name tmp-file 'noquote)))) (if (member "pp" result-params)
((lambda (raw) org-babel-python-pp-wrapper-method
(if (or (member "code" result-params) org-babel-python-wrapper-method)
(member "pp" result-params)) (mapconcat
raw (lambda (line) (format "\t%s" line))
(org-babel-python-table-or-string raw))) (split-string
(org-remove-indentation
(org-babel-trim body))
"[\r\n]") "\n")
(org-babel-process-file-name tmp-file 'noquote))))
(org-babel-eval-read-file tmp-file)))))) (org-babel-eval-read-file tmp-file))))))
(defun org-babel-python-evaluate-session (defun org-babel-python-evaluate-session
@ -248,22 +252,25 @@ last statement in BODY, as elisp."
(mapc (lambda (statement) (insert statement) (comint-send-input)) (mapc (lambda (statement) (insert statement) (comint-send-input))
(split-string (org-babel-trim body) "[\r\n]+")) (split-string (org-babel-trim body) "[\r\n]+"))
(comint-send-input) (comint-send-input))) (comint-send-input) (comint-send-input)))
(case result-type ((lambda (results)
(output (if (or (member "code" result-params)
(mapconcat (member "pp" result-params)
#'org-babel-trim (and (member "output" result-params)
(butlast (not (member "table" result-params))))
(org-babel-comint-with-output results
(session org-babel-python-eoe-indicator t body) (org-babel-python-table-or-string results)))
(let ((comint-process-echoes nil)) (case result-type
(input-body body) (output
(insert org-babel-python-eoe-indicator) (mapconcat
(comint-send-input))) 2) "\n")) #'org-babel-trim
(value (butlast
((lambda (results) (org-babel-comint-with-output
(if (or (member "code" result-params) (member "pp" result-params)) (session org-babel-python-eoe-indicator t body)
results (let ((comint-process-echoes nil))
(org-babel-python-table-or-string results))) (input-body body)
(insert org-babel-python-eoe-indicator)
(comint-send-input))) 2) "\n"))
(value
(let ((tmp-file (org-babel-temp-file "python-"))) (let ((tmp-file (org-babel-temp-file "python-")))
(org-babel-comint-with-output (org-babel-comint-with-output
(session org-babel-python-eoe-indicator nil body) (session org-babel-python-eoe-indicator nil body)