我在尝试添加超链接时遇到以下语法错误,我查看了href的HTML代码,HTML代码似乎正确但是python正在抛出语法错误。有人可以帮忙吗?
Python代码
msg_body=("<HTML><head></head>"
"<body>Test"
"<br>Hi All, <br>"
"<b>Wiki @<a href="%s">%s</a> (listed @ go\link) <br><br>"
"<b>Release notes:</b> %s <br><br>"
"<b>Host/Riva Build Combo:</b><br>%s<br><br>"
"<b>Loading instructions:</b><br>%s<br><br>"
"<b>CR fixes:</b><br>%s<br><br>"
"Thanks,<br>"
"B team"
"</body></html>"
) % (wikiURL,Releasenotes,table,Load_ins,crInfo)
错误: -
"<b>Wiki @<a href="%s">%s</a> (listed @ go\wbit) <br><br>" ^
SyntaxError: invalid syntax
答案 0 :(得分:4)
msg_body="""<HTML><head></head>
<body>Test
<br>Hi All, <br>
<b>Wiki @<a href="%s">%s</a> (listed @ go\link) <br><br>
<b>Release notes:</b> %s <br><br>
<b>Host/Riva Build Combo:</b><br>%s<br><br>
<b>Loading instructions:</b><br>%s<br><br>
<b>CR fixes:</b><br>%s<br><br>
Thanks,<br>
B team
</body></html>
""" % (wikiURL, Releasenotes, table, Load_ins, crInfo)
答案 1 :(得分:0)
要指出的其他事情;你可能想要使用:
<p> & </p>
而不是:
<br>
因为它是一个段落。例如:
<p> Hello world. This is a paragraph.</p>
它也会从最后一项开始。
答案 2 :(得分:0)
错误的行是
"<b>Wiki @<a href="%s">%s</a> (listed @ go\link) <br><br>"
你需要在引号内转义引号:
"<b>Wiki @<a href=\"%s\">%s</a> (listed @ go\link) <br><br>"
像那样:
'<b>Wiki @<a href="%s">%s</a> (listed @ go\link) <br><br>'
或(正如@ragsagar所建议的):
"""
<b>Wiki @<a href="%s">%s</a> (listed @ go\link) <br><br>
"""