[Python-Dev] Why can't I encode/decode base64 without importing a module?

M.-A. Lemburg mal at egenix.com
Tue Apr 23 17:22:35 CEST 2013

On 23.04.2013 17:15, Barry Warsaw wrote:
> On Apr 22, 2013, at 06:22 PM, Guido van Rossum wrote:
>>> You can ask the same question about all the other codecs.  (And that
>>> question has indeed been asked in the past.)
>> Except for rot13. :-)
> The fact that you can do this instead *is* a bit odd. ;)
> from codecs import getencoder
> encoder = getencoder('rot-13')
> r13 = encoder('hello world')[0]

Just as reminder: we have the general purpose
encode()/decode() functions in the codecs module:

import codecs
r13 = codecs.encode('hello world', 'rot-13')

These interface directly to the codec interfaces, without
enforcing type restrictions. The codec defines the supported
input and output types.

Marc-Andre Lemburg

Professional Python Services directly from the Source  (#1, Apr 23 2013)
>>> Python Projects, Consulting and Support ...   http://www.egenix.com/
>>> mxODBC.Zope/Plone.Database.Adapter ...       http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
2013-04-17: Released eGenix mx Base 3.2.6 ...     http://egenix.com/go43

::::: Try our mxODBC.Connect Python Database Interface for free ! ::::::

   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611

More information about the Python-Dev mailing list