Use Python's Built-In Template Strings To Generate Output
March 2022
=
=
=
=
Output:
The value is: quick fox
This is a basic one where you pass it two paths and a data dictionary and it makes the output.
=
And here's a full boiler plate:
=
=
return
=
TL;DR
Create a template file named template.txt like this:
#+BLOCKNAME: template.txt #+begin_src shell :tangle ~/Grimoire/_examples/template.txt
this is the name: $name and the color: $color
#+end_src
Then make this
#+BLOCKNAME: generator.py
#+begin_src python :results output :dir ~/Grimoire/_examples :wrap example :post padder(data=*this*)from string import Template
with open('template.txt') as _tmpl: template = Template(_tmpl.read()) output = template.substitute( name="Karl", color="Green" ) print(output)
#+end_src
Output:
this is the name: Karl
and the color: Green
From A String
=
=
Output:
Name: Karl - Color: Green
#+REFERENCES:
docs: https://docs.python.org/3/library/string.html#template-strings
end of line