str(bytes) in Python 3.0

Carl Banks pavlovevidence at gmail.com
Sun Apr 13 03:24:04 EDT 2008


On Apr 12, 11:51 am, Kay Schluehr <kay.schlu... at gmx.net> wrote:
> On 12 Apr., 16:29, Carl Banks <pavlovevide... at gmail.com> 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.


Whatever happened to the decode method anyway?  Why has str() been
coopted for this purpose?  I had expected that str objects would
retain the encode method, bytes the decode method, and everyone would
live happily ever after.  If decode is a confusing name (and I know I
have to engage a few extra neurons to figure out which way it goes),
why not rename it to something like to_unicode instead of overloading
the constructors more.



Carl Banks



More information about the Python-list mailing list