小编Ces*_*rio的帖子

在 HTML / .format() 中使用 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 = """\
<html xmlns:v="urn:schemas-microsoft-com:vml"
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">

<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<meta name=ProgId content=Word.Document>
<meta name=Generator content="Microsoft Word 15">
<meta name=Originator content="Microsoft Word 15">
<link rel=File-List href="Law_files/filelist.xml">
<!--[if gte mso 9]><xml>

# (...)

-->
</style>
<!--[if gte mso 10]>
<style>
 /* Style …
Run Code Online (Sandbox Code Playgroud)

html python variables string.format

2
推荐指数
1
解决办法
4671
查看次数

标签 统计

html ×1

python ×1

string.format ×1

variables ×1