2

While the command below returns filenames in the commandline, I somehow can't get the same result using org-babel:

#+BEGIN_SRC python :results output
import os
os.listdir(path='.')
#+END_SRC

#+RESULTS:
None

Altering the command e.g. using scandir nor the :results property (value,raw) helped

  • You might want to print the return value of that function so babel can pick it up and show it as results of evaluation. – DoMiNeLa10 Apr 28 at 14:59
2

By using :results value and returning a value, the result will be a list:

#+begin_src python :results value
import os
return os.listdir(path='.')
#+end_src

#+RESULTS:
| python.org | foo.txt | bar.txt |

Returning the results as an org table, as above, makes the results easy to use as the input to other src blocks. But, if you want the result to be formatted like a python list, you can use :results value pp:

#+begin_src python :results value pp
import os
return os.listdir(path='.')
#+end_src

#+RESULTS:
: ['python.org', 'foo.txt', 'bar.txt']

or :results output and print the result:

#+begin_src python :results output
import os
print(os.listdir(path='.'))
#+end_src

#+RESULTS:
: ['python.org', 'foo.txt', 'bar.txt']

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.