Tutorial by Examples

from string import Template data = dict(item = "candy", price = 8, qty = 2) # define the template t = Template("Simon bought $qty $item for $price dollar") print(t.substitute(data)) Output: Simon bought 2 candy for 8 dollar Templates support $-based substitution...
You can change the "$" delimiter to any other. The following example: from string import Template class MyOtherTemplate(Template): delimiter = "#" data = dict(id = 1, name = "Ricardo") t = MyOtherTemplate("My name is #name and I have the id: #id&quot...

Page 1 of 1