branch: externals-release/org
commit a8a0d4ac0ddad342b47660f65a594e3907421826
Author: Jack Kamm <jackk...@gmail.com>
Commit: Jack Kamm <jackk...@gmail.com>

    ob-python: Fix bug preventing users from using variables named "f"
    
    Fixes 
https://list.orgmode.org/75059a24-4e56-4b9d-ab71-1c4db00db...@gmail.com/T/#u
    
    * lisp/ob-python.el (org-babel-python--def-format-value):
    (org-babel-python-evaluate-session): Replace python variable "f" with
    "__org_babel_python_tmpfile", following the convention used in
    `org-babel-python-format-session-value'
---
 lisp/ob-python.el | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/lisp/ob-python.el b/lisp/ob-python.el
index eb5c1379a8..36bc428f52 100644
--- a/lisp/ob-python.el
+++ b/lisp/ob-python.el
@@ -158,14 +158,14 @@ file to save the graphics to.")
 
 (defconst org-babel-python--def-format-value "\
 def __org_babel_python_format_value(result, result_file, result_params):
-    with open(result_file, 'w') as f:
+    with open(result_file, 'w') as __org_babel_python_tmpfile:
         if 'graphics' in result_params:
             result.savefig(result_file)
         elif 'pp' in result_params:
             import pprint
-            f.write(pprint.pformat(result))
+            __org_babel_python_tmpfile.write(pprint.pformat(result))
         elif 'list' in result_params and isinstance(result, dict):
-            f.write(str(['{} :: {}'.format(k, v) for k, v in result.items()]))
+            __org_babel_python_tmpfile.write(str(['{} :: {}'.format(k, v) for 
k, v in result.items()]))
         else:
             if not set(result_params).intersection(\
 ['scalar', 'verbatim', 'raw']):
@@ -198,7 +198,7 @@ def __org_babel_python_format_value(result, result_file, 
result_params):
                             result = result.tolist()
                         else:
                             result = repr(result)
-            f.write(str(result))"
+            __org_babel_python_tmpfile.write(str(result))"
   "Python function to format value result and save it to file.")
 
 (defun org-babel-variable-assignments:python (params)
@@ -495,8 +495,8 @@ non-nil, then save graphical results to that file instead."
             (pcase result-type
              (`output
               (let ((body (format "\
-with open('%s') as f:
-    exec(compile(f.read(), f.name, 'exec'))"
+with open('%s') as __org_babel_python_tmpfile:
+    exec(compile(__org_babel_python_tmpfile.read(), 
__org_babel_python_tmpfile.name, 'exec'))"
                                   (org-babel-process-file-name
                                    tmp-src-file 'noquote))))
                 (org-babel-python-send-string session body)))

Reply via email to