Not enough arguments for format string

R

ronrsr

is the error message I'm getting here, on the long formatted print
statement. . I've tried adding arguments, in case I missed one, and it
still gets a syntax error.

here's the info:

#row is a dictionary with keys: zid, keywords, citation, quotation
def print_row(row):
print row;
print "row in
print_row","kw=",row["keywords"],"q=",row["quotation"],"c =
",row["citation"],"xyzzy row"


print """<tr>
<td class="pad">%s
</td>
<td class="pad">%s
</td>
<td class="pad">%s
</td>
<td class="pad" align="center"><form action="update.cgi"
name="updateform" enctype="application/x-www-form-urlencoded"
method="GET"><input type="hidden" name="zid" value="%d"><input
type="submit" value="Edit"></form>
</td>
</tr>
"""%row['keywords'],row['quotation'],row['citation'],row['zid']
print "done printrow xyzzy"




here's the output, with my debugging info:

{'keywords': 'Agricultural Subsidies, Farmers', 'zid': 319L,
'citation': '\xe2\x80\x9cAgriculture in Crisis,\xe2\x80\x9d
<i>Rethinking US Agricultural Policy: Changing Course to Secure Farmer
Livelihoods Worldwide</i>, September 2003, 9', 'quotation': 'In 2001,
government payments to farmers amounted to an astounding 47 percent of
farmer income, up from about 20 percent in the 1990s. Despite this
enormous infusion of cash, farmer income declined steadily during the
same period, and many US farmers are under increasing financial
stress.'}
row in print_row kw= Agricultural Subsidies, Farmers q= In 2001,
government payments to farmers amounted to an astounding 47 percent of
farmer income, up from about 20 percent in the 1990s. Despite this
enormous infusion of cash, farmer income declined steadily during the
same period, and many US farmers are under increasing financial stress.
c = "Agriculture in Crisis," <i>Rethinking US Agricultural Policy:
Changing Course to Secure Farmer Livelihoods Worldwide</i>, September
2003, 9 xyzzy row
Traceback (most recent call last):
File "C:\Documents and Settings\Ronald\My
Documents\spi\zingers\public_html\display.py", line 116, in ?
zhtml.print_row(adict)
File "C:\Documents and Settings\Ronald\My
Documents\spi\zingers\public_html\zhtml.py", line 222, in print_row
print """<tr>
TypeError: not enough arguments for format string


thanks once again,

-rsr-
 
P

Paul McGuire

Change:

"""%row['keywords'],row['quotation'],row['citation'],row['zid']

to

""" % (row['keywords'],row['quotation'],row['citation'],row['zid'])

-- Paul
 
P

Paul McGuire

ronrsr said:
is the error message I'm getting here, on the long formatted print
statement. . I've tried adding arguments, in case I missed one, and it

print """<tr>
<td class="pad">%s
</td>
<td class="pad">%s
</td>
<td class="pad">%s
</td>
<td class="pad" align="center"><form action="update.cgi"
name="updateform" enctype="application/x-www-form-urlencoded"
method="GET"><input type="hidden" name="zid" value="%d"><input
type="submit" value="Edit"></form>
</td>
</tr>
"""%row['keywords'],row['quotation'],row['citation'],row['zid']
print "done printrow xyzzy"

Another technique is to use named string fields in the interpolation format:

print """<tr>
<td class="pad">%(keywords)s
</td>
<td class="pad">%(quotation)s
</td>
<td class="pad">%(citation)s
</td>
<td class="pad" align="center"><form action="update.cgi"
name="updateform" enctype="application/x-www-form-urlencoded"
method="GET"><input type="hidden" name="zid" value="%(zid)d"><input
type="submit" value="Edit"></form>
</td>
</tr>
""" % row

This style is a bit easier to follow, and later maintain.

-- Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top