Python TypeError: not enough arguments for format string in case of string %s
<pre><code>wrapper = """&lt;html&gt;
&lt;head&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;table style="height: 100px;" width="500"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td rowspan="3"&gt;&lt;a id="imgrec1" href="http://www.w3.org"&gt;&lt;img src="%s" alt="Smiley face" width="50" height="100" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;%s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;%s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;%s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;tr&gt;
&lt;td rowspan="3"&gt;&lt;a id="imgrec1" href="http://www.w3.org"&gt;&lt;img src="%s" alt="Smiley face" width="50" height="100" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;%s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;%s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;%s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;"""

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
</code></pre>

<p>As <code>wrapper</code> has exactly 8 %s and <code>str</code> has also 8 tuples, but still showing error <code>TypeError: not enough arguments for format string.</code></p>

<p>But instead of str, if I use </p>

<pre><code>    whole = wrapper %  
(I["M1"],T["M1"],R["M1"],P["M1"],I["M2"],T["M2"],R["M2"],P["M2"])
</code></pre>

<p>then it is working fine.</p>

<p>I refer <a href="http://stackoverflow.com/questions/24252358/typeerror-not-enough-arguments-for-format-string-when-using-s">stackoverflow</a> <a href="http://stackoverflow.com/questions/11146190/python-typeerror-not-enough-arguments-for-format-string">stackoverflow</a> for this problem, but it did not help.</p>

<p>I suppose you get an error because you pass a string as a single argument when formatting a string.
You can create a list initially:</p>

<pre><code>str = []
for i in reclist[:2]:
    str += [I[i], T[i] etc.]
</code></pre>

<p>and then use:</p>

<pre><code>whole = wrapper % tuple(str)
</code></pre>

<p>so that every item in a list will be passed as a separate argument.</p>

python html string typeerror