Not enough arguments for format string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ronrsr

    #1

    Not enough arguments for format string

    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="updatefor m" enctype="applic ation/x-www-form-urlencoded"
    method="GET"><i nput type="hidden" name="zid" value="%d"><inp ut
    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\x9cAg riculture 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 = "Agricultur e 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:\Documen ts and Settings\Ronald \My
    Documents\spi\z ingers\public_h tml\display.py" , line 116, in ?
    zhtml.print_row (adict)
    File "C:\Documen ts and Settings\Ronald \My
    Documents\spi\z ingers\public_h tml\zhtml.py", line 222, in print_row
    print """<tr>
    TypeError: not enough arguments for format string


    thanks once again,

    -rsr-

  • Paul McGuire

    #2
    Re: Not enough arguments for format string

    Change:

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

    to

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

    -- Paul


    Comment

    • Paul McGuire

      #3
      Re: Not enough arguments for format string

      "ronrsr" <ronrsr@gmail.c omwrote in message
      news:1163991320 .262638.154950@ j44g2000cwa.goo glegroups.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="updatefor m" enctype="applic ation/x-www-form-urlencoded"
      method="GET"><i nput type="hidden" name="zid" value="%d"><inp ut
      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">%(k eywords)s
      </td>
      <td class="pad">%(q uotation)s
      </td>
      <td class="pad">%(c itation)s
      </td>
      <td class="pad" align="center"> <form action="update. cgi"
      name="updatefor m" enctype="applic ation/x-www-form-urlencoded"
      method="GET"><i nput 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


      Comment

      • ronrsr

        #4
        Re: Not enough arguments for format string

        thanks. solution 1 worked like a charm.


        Paul McGuire wrote:
        "ronrsr" <ronrsr@gmail.c omwrote in message
        news:1163991320 .262638.154950@ j44g2000cwa.goo glegroups.com.. .
        is the error message I'm getting here, on the long formatted print

        Comment

        Working...