Where is encode in base64.py ?

Alex Martelli aleax at aleax.it
Sun Mar 16 18:02:07 CET 2003

EleKtR0 wrote:

> Hi!
> I'm trying create a simple mail client with Python, but i have this
> message when run my program:

Your code below has many problems (e.g., you don't CALL the close
methods of the files, you just MENTION them -- add () after each
.close; similarly, INSTANTIATE the SMTP class, again by calling it,
e.g. adding a () after it, don't just GET A REFERENCE to it under
the name 'correo'), but the traceback you're getting depends on
yet another issue, not obvious from the source you post but quite
obvious from the traceback itself:

> Traceback (most recent call last):
>   File "./enviar_cv.py", line 5, in ?
>     from smtplib import SMTP
>   File "/usr/local/lib/python2.3/smtplib.py", line 47, in ?
>     import base64
>   File "/home/jasm/Programacion/base64.py", line 6, in ?
>     base64.encode(f_in,f_out)
> AttributeError: 'module' object has no attribute 'encode'

What's being imported as base64, as the traceback says, is a
file named base64.py in directory /home/jasm/Programacion/ ,
and that file tries calling a function named 'encode' *IN A
MODULE OF THE SAME NAME* (?!) -- presumably thus IN ITSELF
WHILE BEING IMPORTED (??!!) -- and no such function is there.

It's very unlikely that's what you want to do -- I suspect
that what you WANT to import as base64 is, rather, the file
base64.py from directory /usr/local/lib/python2.3/ .  By the
way, since from the many errors I suspect you're not yet very
experienced with Python, I would suggest you use the stable,
solid Python 2.2.2 release, NOT the 2.3 that is still in the
alpha stage -- not a big issue, but, general advice.

Back to your problem: don't name your own modules and scripts
with the same names as standard library ones that you may
want to use (directly or indirectly), or if you do at the
very least make sure that the directories containing your own
modules or scripts are NOT in the import path, PARTICULARLY
not AHEAD of the standard library directory.  But avoiding
name clashes is simpler and safer.

And remember that to CALL an object, ANY object (function,
class, WHATEVER) you need () after that object.  If you just
mention the object, it will NOT be *CALLED*...


More information about the Python-list mailing list