[docs] [issue26369] doc for unicode.decode and str.encode is unnecessarily confusing

Terry J. Reedy report at bugs.python.org
Fri Feb 19 19:29:23 EST 2016

Terry J. Reedy added the comment:

The intended use for str.encode is for same-type transcoding, like this:

I was unaware of the seemingly useless behavior you quote.

>>> 'abc'.encode('base64')
>>> 'YWJj\n'.decode('base64')

Here is a similar use for unicode.decode.

>>> u'abc'.encode('base64')
>>> u'YWJj\n'.decode('base64')

Any doc change should make the intended use clear if not already.

(Note that the above give lookup errors in 3.x
>>> 'abc'.encode('base64')
LookupError: 'base64' is not a text encoding; use codecs.encode() to handle arbitrary codecs)

nosy: +terry.reedy

Python tracker <report at bugs.python.org>

More information about the docs mailing list