我很难让“标记”显示出来。我不知道如何正确使用.format()在字符串内显示标记。在HTML中使用Python变量/ .format()
变量是否需要位于字符串中的特定位置?试图第一次掌握这一点。对不起,如果我问基本问题。
得到:""".format(marker) KeyError: 'font-family'。不确定问题出在哪里。
marker = "AUniqueMarker"
# Create the body of the message (a plain-text and an HTML version).
text = "This is a test message.\nText and html."
html = """\
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:m="http://schemas.microsoft.com/office/2004/12/omml"
xmlns="http://www.w3.org/TR/REC-html40">
{marker}
""".format(marker=marker)
2014-10-20
Cesario
+0
从[文件](HTTPS ://docs.python.org/2/library/string.html#format-string-syntax):如果你需要在文本文本中包含一个大括号字符,它可以通过加倍来转义:'{{'和' }}'。 –
2014-10-20 13:51:55