1

I am trying to use multiple src blocks to explain a yaml config file usage in python. Below is my org file,

#+name: config.yaml
#+begin_src yaml 
name: john
why: check

# below is a dict example
# see it allows comments too
full_name:
  first_name: john
  last_name: smith
#+end_src

Now, let us load this into a python script
#+begin_src python :var input=config.yaml
import yaml

with open(input, 'r') as f:
    cfg = yaml.load(f, Loader=yaml.FullLoader)

print(cfg)
#+end_src

#+RESULTS:

But when I do C-c C-c, I see No org-babel-execute function for yaml!. Can anyone help me identify the error and how to fix it?

Environment: macOs, doom emacs

2 Answers 2

0

It looks like yaml as a language is not supported in source code blocks. At least it is not listed in the Languages Section of the org-manual.

The error message usually means that the language is not loaded by org-babel and you have to load it in your emacs config file (.emacs or init.el) like so:

'(org-babel-load-languages
'((python . t)
  (emacs-lisp . t)))

Adding an option (yaml . t) did not work for me.

I might be wrong here, so correct me if I'm wrong. I'm curious though, did execution of a yaml source code block ever work for you or is it simply not working in the context above?

2
  • Hey @Peter Bamm, Thanks for your response. I haven't tried executing an YAML source code block prior to this. I am newbie to emacs and org mode, so this is all new to me! However, I was able to get a similar version of what I wanted to work. I am adding that as an answer below.
    – gowthamr
    Sep 6, 2021 at 1:43
  • Looks like a great workaround!
    – Peter Bamm
    Sep 6, 2021 at 19:59
0

Not an exact solution, but I was able to get around with shell src block printing the yaml text which then was consumed by the python src block as a variable.

Here are the contents of my org file now.

#+name: config.yaml
#+begin_src sh :exports results :results output
echo """
name: john
why: check

# below is a dict example
# see it allows comments too
full_name:
  first_name: john
  last_name: smith
"""
#+end_src

Now, let us load this into a python script
#+begin_src python :var zzz=config.yaml :results output
import yaml

x = yaml.load(zzz)
print(x)
#+end_src

 #+RESULTS:
: {'name': 'john', 'why': 'check', 'full_name': {'first_name': 'john', 'last_name': 'smith'}}

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.