format requires a mapping?

Fredrik Lundh fredrik at
Mon Nov 13 01:41:40 CET 2006

ronrsr wrote:

> what is python trying to tell me here?  does it have to do with
> formatting the string.
> Keywords and Zinger are fields in my database.
> print """<tr>
>     <td class="padplace" width="120">Keywords</td>
>     <td class="padplace" idth="660">Zinger</td><td>
> TypeError:  format requires a mapping

portions of your code and the traceback appears to be missing, so it's a 
bit hard to tell what you're really doing here, but that error message 
usually means that you're using the % string formatting operator with 
named placeholders in the string template, but with something that's not 
a dictionary as the data.  an example:

 >>> "%(name)s" % 10
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
TypeError: format requires a mapping

either switch to positional markers, or put the data in a dictionary (or 
any other object that implements the mapping interface).


More information about the Python-list mailing list