擅长:python、mysql、java
<p>如果您可以控制模板,我将使用<code>str.format</code>和包含变量的<code>dict</code>:</p>
<pre><code>>>> template = "This {publication} was written by {author}, who is solely responsible for its content."
>>> variables = {"publication": "article", "author": "Me"}
template.format(**variables)
'This article was written by Me, who is solely responsible for its content.'
</code></pre>
<p>很容易将其扩展到字符串列表:</p>
^{pr2}$