1

尝试添加超链接时出现以下语法错误,我查看了 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
4

3 回答 3

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)
于 2012-11-06T04:31:03.583 回答
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>
"""
于 2012-11-07T10:56:08.500 回答
0

还有一点需要指出;您可能想使用:

    <p> & </p>

代替:

    <br>

因为它使一个段落。例如:

    <p> Hello world. This is a paragraph.</p>

它也从最后一个项目中休息。

于 2012-11-07T10:43:43.557 回答