babel: python uses :return header argument

* lisp/ob-python.el (org-babel-execute:python): Use a :return header
  argument for external evaluation in which the code block body need
  be wrapped in a function

Thanks to Darlan Cavalcante for proposing this feature.
This commit is contained in:
Eric Schulte 2010-11-27 23:59:51 +00:00 committed by Dan Davison
parent 039f248092
commit 994e1648e2
1 changed files with 4 additions and 1 deletions

View File

@ -56,9 +56,12 @@ This function is called by `org-babel-execute-src-block'."
(cdr (assoc :session params))))
(result-params (cdr (assoc :result-params params)))
(result-type (cdr (assoc :result-type params)))
(return-val (when (and (eq result-type 'value) (not session))
(cdr (assoc :return params))))
(full-body
(org-babel-expand-body:generic
body params (org-babel-variable-assignments:python params)))
(concat body (if return-val (format "return %s" return-val) ""))
params (org-babel-variable-assignments:python params)))
(result (org-babel-python-evaluate
session full-body result-type result-params)))
(or (cdr (assoc :file params))