[Python-Dev] Why can't I encode/decode base64 without importing a module?

Lennart Regebro regebro at gmail.com
Thu Apr 25 09:03:08 CEST 2013


On Thu, Apr 25, 2013 at 8:57 AM, Stephen J. Turnbull <stephen at xemacs.org> wrote:
> I think that would be an unfortunate result.  These operations on
> streams are theoretically nicely composable.  It would be nice if
> practice reflected that by having a uniform API for all of these
> operations (charset translation, encoded text to internal, content
> transfer encoding, compression ...).  I think it would be useful, too,
> though I can't prove that.

But the translation to and from Unicode to some 8-bit encoding is
different from the others. It makes sense that they have a different
API. If you have a Unicode string you can go:

    Unicode text -> UTF8 -> ZIP -> BASE64.

Or you can go

    Unicode text -> UTF8 -> BASE64 -> ZIP

Although admittedly that makes much less sense. :-)

But you can not go:

   Unicode text -> BASE64 -> ZIP -> UTF8

The str/bytes encoding/decoding is not like the others.

//Lennart


More information about the Python-Dev mailing list