Chris Angelico wrote:
> ANY object can be passed to str() in order to get some sort of valid
> printable form. The awkwardness comes from the fact that str()
> performs double duty - it's both "give me a printable form of this
> object" and "decode these bytes into text".
While it does make sense for str() to be able to give some form of printable form for any object, I suppose that I just don't consider something like this: "b'\\xc3\\xa1'" to be overly useful, at least for any practical purposes. Can anyone think of a situation where you would want a string representation of a bytes object instead of decoding it?
If not, I think it would be more useful for it to either:
1) Raise a TypeError, assume that the user wanted to decode the string but forgot to specify an encoding
2) Implicitly decode the bytes object as UTF-8, assume the user meant str(bytes_obj, encoding='utf-8')
Personally, I'm more in favor of (1) since it's much more explicit and obvious, but I think (2) would at least be more useful than the current behavior.