base64.b64encode(data)
Gregory Ewing
greg.ewing at canterbury.ac.nz
Mon Jun 13 19:12:19 EDT 2016
Chris Angelico wrote:
> Maybe what Python needs is an "ascii" type that's a subclass of both
> str and bytes, and requires that the contents be <0x80. It is text, so
> it can be combined with text strings; but it is also bytes, so when
> you combine it with bytes strings, it'll behave as most people expect.
That would be asking for trouble, I think. It would be
letting back in a bit of the text/bytes confusion that
Python 3 worked hard to get rid of. What happens if the
bytes that you combine it with aren't in an ascii-compatible
encoding? Nothing would detect that error.
The only thing you might gain is a bit of efficiency by
removing some encoding/decoding operations. But since the
FSR, these are pretty cheap anyway when the characters are all
ascii.
They could maybe be made a bit cheaper still by arranging
some way for a bytes object and an ascii-only str object
to share underlying storage.
--
Greg
More information about the Python-list
mailing list