0

How do I wrap each line with a function and collect all value outputs from an org src block and collect all value outputs from an org src block?

For example,

If I have

#+begin_src python
3492-134.2
3492-134.2+1428
#+end_src

I would like

#+RESULTS:
: 3357.8
: 4785.8

Not

#+RESULTS:
: 4785.8

According to https://orgmode.org/manual/Results-of-Evaluation.html, adding :results output to the header will collect every output to the standard stream. But that would require me to add a print statement to each line manually.

1 Answer 1

1

Would changing the input to a table work? Something like this:

#+name: foo
|      3492-134.2 |
| 3492-134.2+1428 |


#+begin_src python :var tbl=foo :results output
  for row in tbl:
    print(eval(row[0]))
#+end_src

#+RESULTS:
: 3357.8
: 4785.8

I think that's about the simplest you can do. You can add entries to the table, but the source block does not need to change.

1
  • +1 for simplicity and ability to use with different languages. Commented Nov 22, 2020 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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