[Python-3000] base64 - bytes and strings

Guido van Rossum guido at python.org
Mon Jul 30 19:24:35 CEST 2007


On 7/30/07, Blake Winton <bwinton at latte.ca> wrote:
> Martin v. Löwis wrote:
> > The debate is whether base64.encodestring (which accepts bytes)
>  > should *produce* (unicode) strings, which would then have to be
>  > encoded as us-ascii. That would make a process of going from
>  > unicode to base64 bytes a three-step process:
> >
> >    tosend = base64.encodestring(data.encode("utf-8")).encode("ascii")
> >
> > Currently, you can spare the last step if you do want bytes,
> > and need to specify .decode("ascii") if you want strings.
>
> As a vote for keeping it, does anyone really want to encode the
> base64-ed data as something other than "ascii"?
>
> I mean, does it make any sense to write:
> tosend = base64.encodestring(data.encode("utf-8")).encode("UTF-16")
> ?  Even if you could, I believe the resulting string would be
> un-processable by any other base-64 decoding tool.

I think you're missing the point, the point being that the most common
use needs bytes, so returning bytes is the most useful API design.

And to answer your rhetorical question: yes, there are other
conceivable encodings for base64; in particular EBCDIC.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list