Python TypeError: non-empty format string passed to object.__format__
I hit this TypeError exception recently, which I found very difficult to debug. I eventually reduced it to this small test case: >>> "{:20}".format(b"hi") Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: non-empty format string passed to object.__format__ This is very non-obvious, to me anyway. The workaround for my code was to decode the byte string into unicode: >>> "{:20}".format(b"hi".decode("ascii")) 'hi ' What is the meaning of this exception? Is there a way it can be made more clear? bytes objects do not have a __format__ method of their own, so the