[Python-Dev] Why does base64 return bytes?

Anders J. Munch andersjm at stofanet.dk
Wed Jun 15 16:42:09 EDT 2016


Paul Moore:
 > Finding out whether users/projects typically write such a helper
 > function for themselves would be a better way of getting this
 > information. Personally, I suspect they don't, but facts beat
 > speculation.

Well, I did. It was necessary to get 2to3 conversion to work(*). I turned every 
occurence of
     E.encode('base-64')
and
    E.decode('base-64')
into helper function calls that for Python 3 did:
    b64encode(E).decode('ascii')
and
    b64decode(E.encode('ascii'))
(Or something similar, I don't have the code in front of me.)

Leaving out .decode/.encode('ascii') would simply not have worked. That would 
just be asking for TypeError's.

regards, Anders

(*) Yes, I use 2to3, believe it or not.  Maintaining Python 2 code and doing an 
automated conversion to Python 3 as needed.



More information about the Python-Dev mailing list