str(bytes) in Python 3.0

Kay Schluehr kay.schluehr at
Sun Apr 13 17:45:21 CEST 2008

On 13 Apr., 09:24, Carl Banks <pavlovevide... at> wrote:
> On Apr 12, 11:51 am, Kay Schluehr <kay.schlu... at> wrote:
> > On 12 Apr., 16:29, Carl Banks <pavlovevide... at> wrote:
> > > > And making an utf-8 encoding default is not possible without writing a
> > > > new function?
> > > 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?
> > How many "encodings" would you define for a Rectangle constructor?
> I'm not sure what you're insinuating.  If you are arguing that it's
> inappropriate for a constructor to take an "encoding" argument (as you
> put it), be my guest.  I wasn't commenting on that specifically.
> I was commenting on your suggestion of having str assume utf-8
> encoding, which IMO would be very unPythonic, whether you can pass
> encodings to it or not.

That's o.k. I don't primarily advocate default values or such things
just reduction of mental and scripting overhead. We shouldn't lose the
goal out of sight. I played a bit with several encodings but this
didn't enable much of an impression how it will feel in real code.

I can see though the inadequacy of my original claim mainly due to the
overlooked fact that there isn't even a mapping of the range \x0 -
\xff to utf-8 but only one from \x0 - \x7f. Same with the ASCII
encoding which is limited to 7 bits as well.

One has to be careful not just because "you can select the wrong
encoding" but stringification with an utf-8 encoding can simply
activate the exception handler even though there will be no type
error! A default value shall work under all circumstances supposed you
pass in an object of the correct type.

More information about the Python-list mailing list