字体表面和颜色语法错误

时间:2012-11-06 05:22:55

标签: python html

我正在尝试添加字体和颜色,并遇到以下错误

#Create the body of the message
msg_body=("<HTML><head></head>"
          "<body>BCC Warning:"
          "<br>Hi All, <br>"
          "<br><br>"
          "<font face = "Arial" color="#990000" > Wiki @<a href=%s>%s</a> (listed @ go\wbit)</font> <br><br>"
          "<b>Release notes:</b> %s  <br><br>" 
          "<b>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>"
          "Build team"
          "</body></html>"
          ) % (wikiURL,wikiURL,Releasenotes,table,Load_ins,crInfo)

语法错误

"<font face = "Arial" > Wiki @<a href=%s>%s</a> (listed @ go\wbit)</font> <br><br>"
                   ^

SyntaxError:语法无效

4 个答案:

答案 0 :(得分:2)

以下面的格式写下

"<font face = 'Arial' > Wiki @<a href=%s>%s</a> (listed @ go\wbit)</font> <br><br>"

但是不建议再使用字体标记了。请改用style='font:arial normal'

更新语法:

msg_body=("<HTML><head></head>"
          "<body>BCC Warning:"
          "<br>Hi All, <br>"
          "<br><br>"
          "<div style='font:Arial normal; color:#990000'> Wiki @<a href=%s>%s</a> (listed @ go\wbit)</div> <br><br>"
          "<b>Release notes:</b> %s  <br><br>" 
          "<b>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>"
          "Build team"
          "</body></html>"
          ) % (wikiURL,wikiURL,Releasenotes,table,Load_ins,crInfo)

答案 1 :(得分:0)

在双引号字符串中为双引号添加斜杠或者您可以使用单引号

"<font face = \"Arial\" style='color:green'> Wiki @<a href=%s>%s</a> (listed @ go\wbit)</font> <br><br>"

答案 2 :(得分:0)

您可以使用&#34; \&#34;跳过引号。

"<font face = \"Arial\" >"

答案 3 :(得分:0)

最简单的解决方法是省略引起错误的引号,写

      "<font face = Arial color=#990000 > Wiki @<a href=%s>%s</a> (listed @ go\wbit)</font> <br><br>

HTML中不需要这些引号。从技术上讲,根据HTML 4.01规范,值#9900000附近需要引号,但浏览器不需要它们(HTML5草稿也不需要)。此外,标记无论如何都是无效的;缺少title元素。