擅长:python、mysql、java
<p>您可以使用在模板或参数中不太可能看到的字符连接所有模板,执行字符串插值,然后分割结果</p>
<pre><code>templates = [
"{} one",
"none",
"{} two {}",
"{} {} three {}",
"one2 {}",
"and {{literal}} braces {{}}"
]
arguments = ["a", "b", "c", "d", "e", "f", "g"]
joined_template = chr(1).join(templates)
formatted_string = joined_template.format(*arguments)
formatted_templates = formatted_string.split(chr(1))
</code></pre>
<p><code>formatted_templates</code>现在是:</p>
<pre><code>['a one',
'none',
'b two c',
'd e three f',
'one2 g',
'and {literal} braces {}']
</code></pre>