you can supply the value-name pairs in a dictionary : Template « String « Python Tutorial






from string import Template


s = Template('A $thing must never $action.')
d = {
  'thing': 'gentleman',
  'action': 'show his socks'
}
s.substitute(d)

print s








5.36.Template
5.36.1.template strings
5.36.2.Interpolating Variables Inside Strings
5.36.3.If the replacement field is part of a word, the name must be enclosed in braces
5.36.4.In order to insert a dollar sign, use $$
5.36.5.you can supply the value-name pairs in a dictionary
5.36.6.template systems (in this case using HTML):