“%”的字符原因导致字符串替换为locals()时出错
我尝试使用python中的locals()替换字符串变量,但我可以找到一种方法在字符串中使用%字符而不会出错。这是一个具体的例子:
color = colors_generator() #the function return a color
html = """<html><head>
<style>#square{color:%(color)s;width:100%;height:100%;}</style>
</head> <body> <div id="square"> </div>
</body></html>""" % locals()
print "Content-Type: text/htmln"
print html
结果:TypeError: not enough arguments for format string
问题是100%的%字符。我该怎么逃避呢?
没有找到相关结果
已邀请:
2 个回复
到街客核
抹持奠糙驰