I'm not 100% sure, but after a quick look at the sources, I think the reason is this:
%, Python , getitem, , , , , , %(name)s. Python . , , bytes lists getitem, :
>>> "xxx" % b'a'
'xxx'
>>> "xxx" % ['a']
'xxx'
:
>>> class X: pass
...
>>> "xxx" % X()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: not all arguments converted during string formatting
>>> class X:
... def __getitem__(self,x): pass
...
>>> "xxx" % X()
'xxx'
- getitem, - "tuplified" :
>>> "xxx" % 'a'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: not all arguments converted during string formatting
, " " , :
>>> "xxx %(0)s" % ['a']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: list indices must be integers, not str
, - , , % .