Search code examples
pythonorg-modeorg-babelorg-table

Pass string argument to a code block from a table in org mode


I'm trying to pass a string as the argument of a code block when using org-mode and org-babel. In particular, I consider the following minimal example:

#+NAME: test
#+BEGIN_SRC python :var x="foobar"
return len(x)
#+END_SRC

| 6 | #ERROR |
#+TBLFM: @1$1='(org-sbe test)::@1$2='(org-sbe test (x ("fb")))

As you can note, the first cell is filled correctly. However, I cannot make the second one be processed correctly. I tried various options; for example:

#+TBLFM: @1$1='(org-sbe test)::@1$2='(org-sbe test (x "fb"))
#+TBLFM: @1$1='(org-sbe test)::@1$2='(org-sbe test(x="fb"))

Any ideas?

BTW: #+CALL: test(x="fb") returns the expected result, i.e. 2. It seems like the syntax for inline calling or "table-calling" is different... :(


Solution

  • Finally found the right combination!

    | 6 | 3 |
    #+TBLFM: @1$1='(org-sbe test)::@1$2='(org-sbe test (x \"bar\"))
    

    Note that the " have to be escaped...