Template strings (as define in PEP292)
We propose the addition of a new class, called Template, which will live in the string module. The Template class supports new rules for string substitution; its value contains placeholders, introduced with the $ character. The following rules for $-placeholders apply:
$$ is an escape; it is replaced with a single $
$identifier names a substitution placeholder matching a mapping key of “identifier”. By default, “identifier” must spell a Python identifier as defined in [2]. The first non-identifier character after the $ character terminates this placeholder specification.
${identifier} is equivalent to $identifier. It is required when valid identifier characters follow > the placeholder but are not part of the placeholder, e.g. “${noun}ification”.
Basically, This is a really simple built-in template engine better C-style %
but way simpler than jinja) as it provide only substitution (ie no expression evaluation). F-string does the same thing but f-string is fixed string.
The support was added in 2.4
from string import Template
ports = ""
params = ""
template = Template('$module #( $params ) $instance($ports);')
txt = template.substitute(module="top", instance="u_top", params =params, ports = ports)