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

how do i map this?

P: n/a
I think I am passing the wrong argument to the Print_row routine:

Traceback (most recent call last):
File "index.py", line 91, in ?
zhtml.print_row(record)
File "/usr/www/users/homebase/realprogress/zingers/zhtml.py", line
154, in pri
nt_row
print """<tr>
TypeError: format requires a mapping
homebase@upsilon%

routine from zhtml.py:

#row is a dictionary with keys: zid, keywords, citation, quotation
def print_row(row):
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.py"
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>
"""
code from index.py:
cursor.execute(querystring);
# get the resultset as a tuple
result = cursor.fetchall()
# iterate through resultset
for record in result:
print record[0] , "-->", record[1]

#zq = zc.query(querystring).dictresult()

#HTML

import zhtml
zhtml.print_start_html()
zhtml.print_header("Frankie's Zingers")

if form.has_key("printview"):
print ("xxxxthenxxxxxx")
zhtml.printp_start_table()
zhtml.printp_title_row()
for record in result:
zhtml.printp_row(record[row])
else:
# print ("xxxxxelsexxxxx",record[1]);
zhtml.print_top_controls(k=k,c=c,q=q)
zhtml.print_start_table()
zhtml.print_title_row()
zhtml.print_search_row(k=k,c=c,q=q)
for record in result:
print(record);
zhtml.print_row(record)

zhtml.print_end_table()
zhtml.print_end_html()


how do i go about mapping that, if tha'ts what I need to do.
thanks again for your help.

bests,

-rsr-

Nov 13 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"ronrsr" <ro****@gmail.comwrites:
#row is a dictionary with keys: zid, keywords, citation, quotation
def print_row(row):
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.py"
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>
"""
You're printing a string, and never using that 'row' parameter.

Perhaps this will help illustrate:
>>print "spam %(foo)s eggs"
spam %(foo)s eggs
>>print "spam %(foo)s eggs" % {'foo': "Wortle"}
spam Wortle eggs

The 'print' statement doesn't care about the format specifiers; it
just wants a string expression. It's the formatting operator, '%',
that looks for them.

<URL:http://docs.python.org/lib/typesseq-strings.html>

--
\ "When I was little, my grandfather used to make me stand in a |
`\ closet for five minutes without moving. He said it was elevator |
_o__) practice." -- Steven Wright |
Ben Finney

Nov 13 '06 #2

P: n/a

Ben Finney wrote:
"ronrsr" <ro****@gmail.comwrites:
#row is a dictionary with keys: zid, keywords, citation, quotation
def print_row(row):
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.py"
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>
"""

You're printing a string, and never using that 'row' parameter.
If that is so, why is he getting that message "TypeError: format
requires a mapping"?

Nov 13 '06 #3

P: n/a
At Monday 13/11/2006 01:55, John Machin wrote:
>Ben Finney wrote:
"ronrsr" <ro****@gmail.comwrites:
#row is a dictionary with keys: zid, keywords, citation, quotation
def print_row(row):
print """<tr>
[...]
"""
You're printing a string, and never using that 'row' parameter.

If that is so, why is he getting that message "TypeError: format
requires a mapping"?
Apparently the posted code doesn't match the actual code. If that
print_row() matched the stack trace, should say % row at the end.
Perhaps there is another function print_row?
Or you cut something from the end?
--
Gabriel Genellina
Softlab SRL

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ˇgratis!
ˇAbrí tu cuenta ya! - http://correo.yahoo.com.ar
Nov 13 '06 #4

P: n/a
ronrsr wrote:
I think I am passing the wrong argument to the Print_row routine:
Well, yes, that is what the error message is telling you.
It is also what Fredrik Lundh told you only a couple of hours ago.
He also told you what to do to fix it, at a high level.
Below is my attempt to explain at a lower level.
If you don't understand, please *reply* to my message; *don't* start a
new topic as though it were a totally fresh problem.

Now read on ...
>
Traceback (most recent call last):
File "index.py", line 91, in ?
zhtml.print_row(record)
File "/usr/www/users/homebase/realprogress/zingers/zhtml.py", line
154, in pri
nt_row
print """<tr>
TypeError: format requires a mapping
homebase@upsilon%

routine from zhtml.py:

#row is a dictionary with keys: zid, keywords, citation, quotation
def print_row(row):
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.py"
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>
"""
This cannot be the code that was executed -- it would need to be
followed by
% row
for it to produce the error message that you received.
>

code from index.py:
cursor.execute(querystring);
# get the resultset as a tuple
result = cursor.fetchall()
# iterate through resultset
for record in result:
print record[0] , "-->", record[1]
"record" looks like a tuple, not a dictionary.
>
#zq = zc.query(querystring).dictresult()

#HTML

import zhtml
zhtml.print_start_html()
zhtml.print_header("Frankie's Zingers")

if form.has_key("printview"):
print ("xxxxthenxxxxxx")
zhtml.printp_start_table()
zhtml.printp_title_row()
for record in result:
zhtml.printp_row(record[row])
else:
# print ("xxxxxelsexxxxx",record[1]);
zhtml.print_top_controls(k=k,c=c,q=q)
zhtml.print_start_table()
zhtml.print_title_row()
zhtml.print_search_row(k=k,c=c,q=q)
for record in result:
print(record);
print is a statement, not a function; you meant
print record
Instead of that, do this
print type(record)
print repr(record)

You will find that "record" is a tuple, not a dictionary
Without changing the code in the zhtml module, you need to make a
dictionary, for example (untested):

adict = {}
for key, inx in zip("zid keywords citation quotation".split(), (0, 1,
2, 3)):
adict[key] = record[inx]
zhtml.print_row(adict)
where (0, 1, 2, 3) are the positions of the 4 fields in record --
change the numbers as necessary to match reality.

Alternatively (sketch):

(1) unpack the tuple e.g.
zid, keywords, citation, quotation = record
# Add names for any other fields that exist.
# Change the order as necessary to match reality.
(2) call a changed zhtml routine:
zhtml.print_row(zid, keywords, citation, quotation)
(3) re-jig the zhtml.print_row routine
def print_row(zid, keywords, citation, quotation):
print """<tr>
<td class="pad">%s
</td>
<td class="pad">%s
etc etc
""" % (keywords, quotation, citation, zid)
zhtml.print_row(record)

zhtml.print_end_table()
zhtml.print_end_html()
HTH,
John

Nov 13 '06 #5

P: n/a
"John Machin" <sj******@lexicon.netwrites:
Ben Finney wrote:
You're printing a string, and never using that 'row' parameter.

If that is so, why is he getting that message "TypeError: format
requires a mapping"?
No idea. Probably because what the poster showed us is not code that
shows the problem described.

Original poster (and everyone who wants help with their program
behaving unexpectedly): please ensure that you post a complete,
minimal example of code that exhibits the unexpected behaviour.

--
\ "Room service? Send up a larger room." -- Groucho Marx |
`\ |
_o__) |
Ben Finney

Nov 13 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.