Confused by "format requires a mapping"

  • Thread starter contact.morrison
  • Start date
C

contact.morrison

Hello,

I'm very new to Python, and unsure how to handle this runtime error
below. Pointers in the right direction (RTFM here ... etc) most
appreciated.

I have an object, called article, that when printed has the following
structure:

{'title': 'wbk', 'entries': [('http://wbk.opendarwin.org/blog/?p=51',
1), ('http://wbk.opendarwin.org/blog/?p=48', 1),
('http://wbk.opendarwin.org/blog/?p=50', 1),
('http://wbk.opendarwin.org/blog/?p=49',1),
('http://wbk.opendarwin.org/blog/?p=45', 1),
('http://wbk.opendarwin.org/blog/?p=44', 1),
('http://wbk.opendarwin.org/blog/?p=43', 1),
('http://wbk.opendarwin.org/blog/?p=42', 1),
('http://wbk.opendarwin.org/blog/?p=41',1),
('http://wbk.opendarwin.org/blog/?p=40',
1)]}('http://wbk.opendarwin.org/blog/?p=51', 1)
DEBUG: Above was a dump of article, prior to "return
unicode("%(title)s"%article)"

As mentioned in the DEBUG output, my code now returns the following
string:

unicode("%(title)s"%article)

However, that appears to conflict with article's structure, and i don't
know why? I'm probably missing something fundamental with Python's
syntax?

TIA
Morrison

Traceback (most recent call last):
File "C:\APPS\pys60\s60-compat\appuifw.py", line 287, in OnSelect
self.callback()
File "wbk.py", line 189, in handle_feedmenu_select
self.goto_state('articlemenu')
File "wbk.py", lineA 156, in goto_state
self.articlemenu.set_list(
File "wbk.py", line 240, in format_article_title
return unicode("%(title)s"%article)
TypeError: format requires a mapping
 
F

Fredrik Lundh

I'm very new to Python, and unsure how to handle this runtime error
below. Pointers in the right direction (RTFM here ... etc) most
appreciated.

I have an object, called article, that when printed has the following
structure:

{'title': 'wbk', 'entries': [('http://wbk.opendarwin.org/blog/?p=51',
1), ('http://wbk.opendarwin.org/blog/?p=48', 1),
('http://wbk.opendarwin.org/blog/?p=50', 1),
('http://wbk.opendarwin.org/blog/?p=49',1),
('http://wbk.opendarwin.org/blog/?p=45', 1),
('http://wbk.opendarwin.org/blog/?p=44', 1),
('http://wbk.opendarwin.org/blog/?p=43', 1),
('http://wbk.opendarwin.org/blog/?p=42', 1),
('http://wbk.opendarwin.org/blog/?p=41',1),
('http://wbk.opendarwin.org/blog/?p=40',
1)]}('http://wbk.opendarwin.org/blog/?p=51', 1)
DEBUG: Above was a dump of article, prior to "return
unicode("%(title)s"%article)"

As mentioned in the DEBUG output, my code now returns the following
string:

unicode("%(title)s"%article)

However, that appears to conflict with article's structure, and i don't
know why? I'm probably missing something fundamental with Python's
syntax?

the debug output shows a dictionary followed by a tuple, rather than a
single value. maybe you should doublecheck what you're really passing
to the % formatting operator...

</F>
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top