ob-ipython icon indicating copy to clipboard operation
ob-ipython copied to clipboard

RESULTS: return lisp form rather than python representations of results

Open cleemesser opened this issue 8 years ago • 2 comments
trafficstars

Hello ob-ipython looks like a fantastic tool. I installed it and it looks great. It seems though to return emacs lips results instead of the python representation of the results. Tracing through the code, it looks like ob-python.el does a conversion. I am not a regular emacs lisp user and a I am new to org-mode so I apologize if I am missing something obvious.

I am using a fresh install of org 9.03 and git clone of ob-ipython (I get the same results with elpa install). I am using emacs 25.1.1 on Mac OS (emacs-plus build in home brew)

Examples of how to use results collection and type in headers

#+TBLNAME: data_table | a | 1 | 2 | | b | 2 | 3 | | c | 3 | 4 |

#+BEGIN_SRC ipython :session :exports both :var x=2 :var data=data_table (x, data) #+END_SRC

#+RESULTS: | 2 | ((a 1 2) (b 2 3) (c 3 4)) |

  • raw - ":results output raw" - gets rid of formating

#+BEGIN_SRC ipython :session :exports both :var x=2 :var data=data_table :results output raw print("example of output") (x, data, [[1,2],3]) #+END_SRC

#+RESULTS: example of output

  • output - capture stdout - ":results output" by itself

#+BEGIN_SRC ipython :session :exports both :var x=2 :var data=data_table :results output print("example of output") (x, data, [[1,2],3]) #+END_SRC

#+RESULTS: : example of output example of output

  • just ":results value" by itself - stdout will now pop up in a buffer

#+BEGIN_SRC ipython :session :exports both :var x=2 :var data=data_table :results value print("example of output") (x, data, [[1,2],3]) #+END_SRC

#+RESULTS: | 2 | ((a 1 2) (b 2 3) (c 3 4)) | ((1 2) 3) |

  • pretty printing? - ":results value pp"

#+BEGIN_SRC ipython :session :exports both :var x=2 :var data=data_table :results value pp (x, data, [[1,2],3]) #+END_SRC

#+RESULTS: | 2 | ((a 1 2) (b 2 3) (c 3 4)) | ((1 2) 3) |

  • "results value drawer"

#+BEGIN_SRC ipython :session :exports both :var x=2 :var data=data_table :results value drawer (x, data, [[1,2],3]) #+END_SRC

#+RESULTS: :RESULTS: | 2 | ((a 1 2) (b 2 3) (c 3 4)) | ((1 2) 3) | :END:

  • "results value code"

#+BEGIN_SRC ipython :session :exports both :var x=2 :var data=data_table :results value code (x, data, [[1,2],3]) #+END_SRC

#+RESULTS: #+BEGIN_SRC ipython | 2 | ((a 1 2) (b 2 3) (c 3 4)) | ((1 2) 3) | #+END_SRC

  • "results value raw"

#+BEGIN_SRC ipython :session :exports both :var x=2 :var data=data_table :results value raw (x, data, [[1,2],3]) #+END_SRC

#+RESULTS: | 2 | ((a 1 2) (b 2 3) (c 3 4)) | ((1 2) 3) |

  • ":results value verbatim"

#+BEGIN_SRC ipython :session :exports both :var x=2 :var data=data_table :results value verbatim (x, data, [[1,2],3]) #+END_SRC

#+RESULTS: | 2 | ((a 1 2) (b 2 3) (c 3 4)) | ((1 2) 3) |

  • ":results value list"

#+BEGIN_SRC ipython :session :exports both :var x=2 :var data=data_table :results value list (x, data, [[1,2],3]) #+END_SRC

#+RESULTS:

  • 2
  • (("a" 1 2) ("b" 2 3) ("c" 3 4))
  • ((1 2) 3)

cleemesser avatar Dec 27 '16 04:12 cleemesser

ob-ipython--table-or-string (results) calls (org-babel-python-table-or-string results) which is what changes things to lisp. just having it return the results string restores the expected behavior

cleemesser avatar Dec 29 '16 17:12 cleemesser

I'm not seeing #+RESULTS: being converted into lisp, but they are converted to an org table. As @cleemesser mentioned, ob-ipython--table-or-string (and thus org-babel-python-table-or-string) is called regardless of the :results header arguments (e.g., verbatim, raw, etc). Possibly related to the recent release of org-mode 9?

org-version: 9.0.4; emacs-version: 26.0.50.2; anaconda python3

singletS avatar Feb 09 '17 01:02 singletS