1

As follow code,can I get a list for other code block?

#+name: test
#+BEGIN_SRC python -n  :exports both
for i in range(5):
    return i
#+END_SRC

#+RESULTS: test
: 0
2

You could just return a list.

#+name: test
#+begin_src python -n
retval = []
for i in range(5):
    retval.append(i)
return retval
#+end_src

#+begin_src python -n :var x=test
retval = []
for j in x:
    retval.append(j+42)
return retval
#+end_src

BTW you could return a list more directly without using a loop like e.g.

#+name: testb
#+begin_src python -n
return [1, 2, 3, 1000]
#+end_src

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.