4

Is it possible to tangle #+RESULTS: block? For example,

#+BEGIN_SRC rst :tangle ./test.txt :noweb yes
<<Tangle_Test>>
#+END_SRC

#+BEGIN_SRC python :exports results :results output raw
print("Results")
#+END_SRC

#+RESULTS: 
Results

And I want to tangle #+RESULTS: part, not the actual Python source code.


Following radebrecht's answer, here is a working example:

#+BEGIN_SRC rst :tangle  ./test.txt :noweb yes
<<Tangle_Test>>
#+END_SRC

#+BEGIN_SRC python :results output code :tangle no :results_switches ":tangle no :noweb-ref Tangle_Test"
print("Print Results")
#+END_SRC

If you evaluate the code block (C-c C-c), then the following #+RESULTS block will be generated:

#+RESULTS:
#+BEGIN_SRC python :tangle no :noweb-ref Tangle_Test
Print Results
#+END_SRC

Then you can tangle the file (org-babel-tangle) and the resulting test.txt will contain Print Results only.

4

Try the :results and :results_switchesparameters:

#+BEGIN_SRC python :results output code :results_switches ":tangle test.py"
print("Results")
#+END_SRC

#+RESULTS:
#+BEGIN_SRC python :tangle test.py
Results
#+END_SRC

Unfortunately this only seems to work with the resulting block using the same language as the code-generator. If you want to switch languages or use the results as data in another block, have a look at the :var parameter.

  • Thanks a lot - this works. I think using the same language is not a problem, as I can just use different file extension for the target file (e.g, test.txt instead of test.py). – joon Jun 22 '15 at 19:13
3

Actually it was explained in the documentation of Noweb reference syntax (I cannot believe I missed this):

It is possible to include the results of a code block rather than the body. This is done by appending parenthesis to the code block name which may optionally contain arguments to the code block as shown below.

 <<code-block-name(optional arguments)>>

If you specify <<code-block-name()>>, it will evaluate the specified code block and tangle only the results.

Only caveat is that you have to use different code-block-name for the code blocks that you actually want to tangle the source. In that sense, radebrecht's answer is also good since you can use one name for all code blocks, you just need to specify :results_switches for the blocks which you want to tangle their results.

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.