str(bytes) in Python 3.0

Christian Heimes lists at cheimes.de
Sat Apr 12 10:59:17 EDT 2008


Carl Banks schrieb:
> I believe the Zen in effect here is, "In the face of ambiguity, refuse
> the temptation to guess."  How do you know if the bytes are utf-8
> encoded?

Indeed

> I'm not sure if str() returning the repr() of a bytes object (when not
> passed an encoding) is the right thing, but it's probably better than
> throwing an exception.  The problem is, str can't decide whether it's
> a type conversion operator or a formatted printing function--if it
> were strongly one or the other it would be a lot more obvious what to
> do.

I was against it and I also wanted to have 'egg' == b'egg' raise an
exception but I was overruled by Guido. At least I was allowed to
implement the byte warning feature (-b and -bb arguments). I *highly*
recommend that everybody runs her unit tests with the -bb option.

Christian




More information about the Python-list mailing list