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

Antoine Pitrou solipsis at pitrou.net
Thu Apr 25 14:38:31 CEST 2013

Le Thu, 25 Apr 2013 12:46:43 +0200,
Xavier Morel <catch-all at masklinn.net> a écrit :

> On 2013-04-25, at 11:25 , Antoine Pitrou wrote:
> > 
> > Besides, I would consider a RFC more authoritative than a
> > Wikipedia definition.
> > Base encoding of data is used in many situations to store or
> > transfer data in environments that, perhaps for legacy reasons, are
> > restricted to US-ASCII [1] data.
> so the output is US-ASCII data, a byte stream.

Well, depending on the context, US-ASCII can be a character set or a
character encoding. If some specification is talking about text and
characters, then it is something that can reasonably be a str in
Python land.

Similarly, we have chosen to make filesystem paths str by default in
Python 3, even though many Unix-heads would claim that filesystem paths
are "bytes only". The reason is that while they are technically bytes
(under Unix), they are functionally text.

Now, if the base64-encoded data is your entire payload, this clearly
amounts to nitpicking. But when you want to *embed* that data in some
larger chunk of text (e.g. a JSON object), then it makes a lot of sense
to consider the base64-encoded data a piece of *text*, not bytes.



More information about the Python-Dev mailing list