Question

Check out the bytes-to-bytes and string-to-string encodings in Python 3:

http://docs.python.org/3/library/codecs.html#standard-encodings (Search for bytes-to-bytes)

How do I use these? I've tried using them in .encode and .decode but it didn't work.

Was it helpful?

Solution

Accessing them through the codecs module by a non-alias name seems to work, in Python 3.2 and above:

>>> import codecs
>>> codecs.decode(b"asdf", "base64_codec")
b'j\xc7_'
>>> codecs.encode(b"asdf", "base64_codec")
b'YXNkZg==\n'
>>> 

Using an alias name ("base64"), Python < 3.2, or bytes.decode all seem to fail.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top