這個問題已經回答過了,但我的字符串沒有任何額外的大括號那會弄亂格式,所以此刻的我,爲什麼錯誤Python中的String.Format KeyError異常
完全無能錯誤是KeyError異常:內容
html = """
<table class=\"ui celled compact table\" model=\"{model}\">
{theaders}
<tbody>
{content}
</tbody>
</table>
"""
html = html.format(model=model)
html = html.format(content=data)
html = html.format(theaders=theaders)
*旁白*:本例中不需要反斜槓。三重引用一個字符串的好處之一是任何單獨的引用字符不再是特殊的。 –
我只是做了他們,試圖找出錯誤的一部分:) – Mojimi