0

My emacs is 29.2 in linux. I try below code to use output from first python block, but the output in second block is None after press C- C-c.

#+name: testblock
#+begin_src python
print("hello")
#+end_src

#+begin_src python :var x=testblock :results ouput 
print(x)
#+end_src

I would expect it output Hello

1
  • Evaluate the first block by pressing C-c C-c on it. What do you get? Does that help explain what you see?
    – NickD
    Commented Mar 28 at 11:41

1 Answer 1

2

The default :results header is value. So, org gets the value by wrapping the code in a function definition in the language of the source block. Code should execute like a function and return a value.

In the first block, you are not returning anything and so its value is taken as None and fed to the second block.

I suggest you to change your code as below,

#+name: testblock 
#+begin_src python :results output
print( "hello" )
#+end_src

#+begin_src python :var x=testblock :results output 
print(x)
#+end_src

or alternatively, you can remove the results header & just use return instead of print.

1
  • 1
    "The default :results header is value" - yes, for Python (and most other languages); but not for every language - e.g. for shell the default is output. It is safest to explicitily specify what you want in all cases.
    – NickD
    Commented Mar 29 at 13:10

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.