base64 module

Roy Smith roy at
Fri Aug 8 21:33:37 CEST 2003

Ken Fettig <kfettig at> wrote:
>Hello, I am trying to make use of the base64 module but am having problems.
>>>> import base64
>>>> decodestring('SVNBKjAwKiAgICAgICAgICAqMDAqICAgICAg')
>Traceback (most recent call last):
>  File "<pyshell#1>", line 1, in ?
>    decodestring('SVNBKjAwKiAgICAgICAgICAqMDAqICAgICAg')
>NameError: name 'decodestring' is not defined
>What am I doing wrong. I am importing the base64 module, why can't I call
>the decodestring method?

All the import statement does is make the base64 module available, but
the objects in that module are still in the base64 namespace.  You
need to do:

>>> base64.decodestring('SVNBKjAwKiAgICAgICAgICAqMDAqICAgICAg')
'ISA*00*          *00*      '

Alternatively, you could do "from base64 import decodestring" (or
even, "from base64 import *", and then you can do:

>>> from base64 import decodestring
>>> decodestring('SVNBKjAwKiAgICAgICAgICAqMDAqICAgICAg')
'ISA*00*          *00*      '

My personal preference is to use the plain version of the import
statement, and use fully qualified names, but it's really up to you
which way you want to do it.

More information about the Python-list mailing list