2.2. String Template

  • Simple string substitution mechanism

  • Uses placeholders in the form of $placeholder

  • from string import Template

  • Do not confuse it with string.templatelib.Template

>>> from string import Template
>>>
>>> template = Template("Hello, $name! Today is $day.")
>>> template.substitute(name="Alice", day="Friday")
'Hello, Alice! Today is Friday.'