summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Schulte <schulte.eric@gmail.com>2011-04-14 20:24:10 -0600
committerEric Schulte <schulte.eric@gmail.com>2011-04-14 20:24:10 -0600
commit28b325fa1e749bfa5ede155e32705571cf851042 (patch)
treedee86f00b5c3a9dae3e854bb140cc7836964ef3e
parentb99ab9250b8c90b9cacc98b15d179c98507704ca (diff)
downloadorg-mode-28b325fa1e749bfa5ede155e32705571cf851042.tar.gz
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".
-rw-r--r--lisp/ob-python.el85
1 files changed, 46 insertions, 39 deletions
diff --git a/lisp/ob-python.el b/lisp/ob-python.el
index a5ce25a..f3f4a03 100644
--- a/lisp/ob-python.el
+++ b/lisp/ob-python.el
@@ -202,29 +202,33 @@ open('%s', 'w').write( pprint.pformat(main()) )")
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."
- (case result-type
- (output (org-babel-eval org-babel-python-command
- (concat (if preamble (concat preamble "\n") "") body)))
- (value (let ((tmp-file (org-babel-temp-file "python-")))
- (org-babel-eval org-babel-python-command
- (concat
- (if preamble (concat preamble "\n") "")
- (format
- (if (member "pp" result-params)
- org-babel-python-pp-wrapper-method
- org-babel-python-wrapper-method)
- (mapconcat
- (lambda (line) (format "\t%s" line))
- (split-string
- (org-remove-indentation
- (org-babel-trim body))
- "[\r\n]") "\n")
- (org-babel-process-file-name tmp-file 'noquote))))
- ((lambda (raw)
- (if (or (member "code" result-params)
- (member "pp" result-params))
- raw
- (org-babel-python-table-or-string raw)))
+ ((lambda (raw)
+ (if (or (member "code" result-params)
+ (member "pp" result-params)
+ (and (member "output" result-params)
+ (not (member "table" result-params))))
+ raw
+ (org-babel-python-table-or-string (org-babel-trim raw))))
+ (case result-type
+ (output (org-babel-eval org-babel-python-command
+ (concat (if preamble (concat preamble "\n") "")
+ body)))
+ (value (let ((tmp-file (org-babel-temp-file "python-")))
+ (org-babel-eval
+ org-babel-python-command
+ (concat
+ (if preamble (concat preamble "\n") "")
+ (format
+ (if (member "pp" result-params)
+ org-babel-python-pp-wrapper-method
+ org-babel-python-wrapper-method)
+ (mapconcat
+ (lambda (line) (format "\t%s" line))
+ (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))))))
(defun org-babel-python-evaluate-session
@@ -248,22 +252,25 @@ last statement in BODY, as elisp."
(mapc (lambda (statement) (insert statement) (comint-send-input))
(split-string (org-babel-trim body) "[\r\n]+"))
(comint-send-input) (comint-send-input)))
- (case result-type
- (output
- (mapconcat
- #'org-babel-trim
- (butlast
- (org-babel-comint-with-output
- (session org-babel-python-eoe-indicator t body)
- (let ((comint-process-echoes nil))
- (input-body body)
- (insert org-babel-python-eoe-indicator)
- (comint-send-input))) 2) "\n"))
- (value
- ((lambda (results)
- (if (or (member "code" result-params) (member "pp" result-params))
- results
- (org-babel-python-table-or-string results)))
+ ((lambda (results)
+ (if (or (member "code" result-params)
+ (member "pp" result-params)
+ (and (member "output" result-params)
+ (not (member "table" result-params))))
+ results
+ (org-babel-python-table-or-string results)))
+ (case result-type
+ (output
+ (mapconcat
+ #'org-babel-trim
+ (butlast
+ (org-babel-comint-with-output
+ (session org-babel-python-eoe-indicator t body)
+ (let ((comint-process-echoes nil))
+ (input-body body)
+ (insert org-babel-python-eoe-indicator)
+ (comint-send-input))) 2) "\n"))
+ (value
(let ((tmp-file (org-babel-temp-file "python-")))
(org-babel-comint-with-output
(session org-babel-python-eoe-indicator nil body)