If a format string includes conversion specifiers of the form %(name)s then the right hand side of the operation must be a mapping. A string is a format string if it appears on the left of a modulo (%) operator, the right hand side being the value to be formatted. If the right hand side is not a mapping then a TypeError will be raised. Mappings are usually dicts but can be any type that implements the mapping protocol.

Change the format to match the arguments and ensure that the right hand side is always a mapping.

In the following example the right hand side of the formatting operation can be a tuple, which is not a mapping. To fix this example, ensure that args is a mapping when unlike_condition occurs.

  • Python Library Reference: String Formatting.