Missing codecs in Python 3.0

samwyse samwyse at gmail.com
Tue Jun 2 22:15:50 EDT 2009


I have a Python 2.6 program (a code generator, actually) that tries
several methods of compressing a string and chooses the most compact.
It then writes out something like this:
  { encoding='bz2_codec', data = '...'}

I'm having two problems converting this to Py3.  First is the absence
of the bz2_codec, among others.  It was very convenient for my program
to delay selection of the decoding method until run-time and then have
an easy way to load the appropriate code.  Is this gone forever from
the standard libraries?

Second, I would write my data out using the 'string_escape' codec.
It, too, has been removed; there's a 'unicode_escape' codec which is
similar, but I would rather use a 'byte_escape' codec to produce
literals of the form b'asdf'.  Unfortunately, there isn't one that I
can find.  I could use the repr function, but that seems less
efficient.  Does anyone have any ideas?  Thanks.



More information about the Python-list mailing list