<p>我有这样的情况。在</p>
<pre><code>a={'x':'test'}
b="this is a %(a['x'])s
print b % {'test':'testing'}
</code></pre>
<p>期望的结果是</p>
^{pr2}$
<p>但它抛出一个错误“ValueError:incomplete format key”</p>
<p>请给我推荐一个更好的好的。谢谢提前。在</p>
<p>需要再创建一个字典。在</p>
<pre><code>>>> a={'x':'test'}
>>> b="this is a %s"
>>> c = {'test':'testing'}
>>> print b % c[a['x']]
this is a testing
</code></pre>