Steven D'Aprano <steve+pyt...@pearwood.info> added the comment:
Encoding and decoding, in the most general sense, can include unicode -> unicode and bytestring -> bytestring. I can't see any standard unicode->unicode encodings in Python 2.7 https://docs.python.org/2/library/codecs.html but we can create one: py> import codecs py> class NullCodec(codecs.Codec): # "do nothing" codec ... def encode(self, input, errors='strict'): ... return (input, len(input)) ... def decode(self, input, errors='strict'): ... return (input, len(input)) ... py> def getregentry(name): ... return codecs.CodecInfo( ... name='null', ... encode=NullCodec().encode, ... decode=NullCodec().decode, ... incrementalencoder=None, ... incrementaldecoder=None, ... streamwriter=None, ... streamreader=None, ... ) ... py> codecs.register(getregentry) py> u'unicode text'.encode('null') u'unicode text' so the documentation is correct, and the Stackoverflow answer is not. ---------- nosy: +steven.daprano _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue35544> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com