Typically, formatting strings in the style of old Python complains if the number of placeholders in the string does not match the number of arguments passed:
>>> 'no.placeholders.here' % 'test'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: not all arguments converted during string formatting
However, when the argument passed is an instance of a user-defined class, it silently ignores it instead:
>>> class Test(object): pass
>>> 'no.placeholders.here' % Test()
'no.placeholders.here'
This behavior seems inconsistent and has led to some complex errors. Why does the type of format argument matter for this error?
source
share