【发布时间】:2017-01-19 11:04:57
【问题描述】:
wrapper = """<html>
<head>
</head>
<body>
<table style="height: 100px;" width="500">
<tbody>
<tr>
<td rowspan="3"><a id="imgrec1" href="http://www.w3.org"><img src="%s" alt="Smiley face" width="50" height="100" /><br /><br /></a></td>
<td>%s</td>
</tr>
<tr>
<td>%s</td>
</tr>
<tr>
<td>%s</td>
</tr>
<tr>
<tr>
<td rowspan="3"><a id="imgrec1" href="http://www.w3.org"><img src="%s" alt="Smiley face" width="50" height="100" /><br /><br /></a></td>
<td>%s</td>
</tr>
<tr>
<td>%s</td>
</tr>
<tr>
<td>%s</td>
</tr>
<tr>
</tbody>
</table>
</body>
</html>"""
str=""
for i in reclist[:2]:
str=str + "I[\"" + i + "\"]," + "T[\"" + i + "\"]," +"R[\"" + i + "\"]," +"P[\"" + i + "\"],"
str = str[:-1]
print str
whole = wrapper % (str)
Output: I["M1"],T["M1"],R["M1"],P["M1"],I["M2"],T["M2"],R["M2"],P["M2"]
whole = wrapper % (str)
TypeError: not enough arguments for format string
wrapper 正好有 8 个 %s,str 也有 8 个元组,但仍然显示错误 TypeError: not enough arguments for format string.
但是如果我使用
而不是 str whole = wrapper %
(I["M1"],T["M1"],R["M1"],P["M1"],I["M2"],T["M2"],R["M2"],P["M2"])
然后它工作正常。
我向stackoverflow stackoverflow 咨询了这个问题,但没有帮助。
【问题讨论】:
-
请发布一个简单的
wrapper = "..."; str = ...; output = wrapper % str示例。
标签: python html string typeerror