1

Let's take this simple Org code, with two Python code blocs (one which returns a list, and the other one which prints the type and the content of the parameter):

#+NAME: int
#+BEGIN_SRC python :results value
return [1, 2, 3]
#+END_SRC

#+NAME: print_table_info
#+BEGIN_SRC python :var table=[]
print "type = {}".format(type(table))
print "table = {}".format(table)
#+END_SRC

#+CALL: print_table_info(table=int) :results output

Executing the #+CALL: will produce the expected result:

#+RESULTS:
: type = <type 'list'>
: table = [1, 2, 3]

Now let's assume I want to execute this directly in emacs-lisp with org-sbe. I would have:

#+BEGIN_SRC emacs-lisp :results output
(org-sbe print_table_info ":results output" (table (org-sbe int)))
#+END_SRC

And executing this code block would produce:

#+RESULTS:
: 
: (results (quote (1 2 3)))
: 
: (results (type = <type 'str'>
: table = (1 2 3)
: "))

Two issues here, which are related:

  1. This result shows that a list was not given to the print_table_info code block but instead a string. How can I actually pass a list?
  2. How could I get rid from the Lisp code in the output of org-sbe and just get the plain output as when I execute the #+CALL:?

Thanks for your help!

1

Actually the issue is that org-sbe returns a string that represents a list. For instance it returns "(1 2 3)" instead of (1 2 3). Thus we need to convert the string back to a list, which was answered somewhere else, with read-from-string.

Thus the emacs-lisp source block becomes:

#+BEGIN_SRC emacs-lisp :results output
(org-sbe print_table_info ":results output" (table (car (read-from-string (org-sbe int)))))
#+END_SRC

And it returns the expected result:

#+RESULTS:
: type = <type 'list'>
: table = [1, 2, 3]

If anyone has a more elegant solution, I'm interested!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.