By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,965 Members | 1,631 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,965 IT Pros & Developers. It's quick & easy.

Not enough arguments for format string

P: n/a
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-

Nov 20 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Change:

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

to

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

-- Paul
Nov 20 '06 #2

P: n/a
"ronrsr" <ro****@gmail.comwrote in message
news:11**********************@j44g2000cwa.googlegr oups.com...
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
Nov 20 '06 #3

P: n/a
thanks. solution 1 worked like a charm.
Paul McGuire wrote:
"ronrsr" <ro****@gmail.comwrote in message
news:11**********************@j44g2000cwa.googlegr oups.com...
is the error message I'm getting here, on the long formatted print
Nov 20 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.