Browse Source

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".
Eric Schulte 14 years ago
parent
commit
28b325fa1e
1 changed files with 46 additions and 39 deletions
  1. 46 39
      lisp/ob-python.el

+ 46 - 39
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)