[Python-Dev] Easy codec access

M.-A. Lemburg mal@lemburg.com
Tue, 15 May 2001 14:10:16 +0200


I've just checked in a set of patches which implement the new
.decode() method along with a couple of useful codecs.

You can now do things like these:

>>> "abc".encode('zlib').encode('base64')
'eJxLTEoGAAJNASc=\n'
>>> _.decode('base64').decode('zlib')
'abc'

>>> "abcäöü".decode('latin-1')
u'abc\xe4\xf6\xfc'

>>> "abcäöü".decode('latin-1').encode('latin-1')
'abc\xe4\xf6\xfc'

>>> "Hello World !".encode('rot13')
'Uryyb Jbeyq !'

So the overall codec experience should be a much better one
now.

To see just how easy it is to write codecs, please have
a look at the string codecs I added in this patch (e.g.
zlib_codec.py or hex_codec.py). I am pretty sure that there
are a lot more useful things in the standard lib which could
benefit from these easy-to-use interfaces.

-- 
Marc-Andre Lemburg
______________________________________________________________________
Company & Consulting:                           http://www.egenix.com/
Python Software:                        http://www.lemburg.com/python/