Strange import bug

Adeodato Simó asp16 at alu.ua.es
Mon Nov 24 18:57:13 EST 2003


* Colin Brown [Tue, 25 Nov 2003 12:41:52 +1300]:

> "Adeodato Simó" <asp16 at alu.ua.es> wrote in message
> news:mailman.1043.1069714565.702.python-list at python.org...
> ...
> The first (default) entry in sys.path is '', which means (I think) the
> current directory. So sys.path.append('./abc') appends after this entry;
> then, on "import abc", python uses first '' entry, which means it looks
> under current directory where it finds "abc" which gets imported *as a
> module*.
> ...

> Okay, but why does python not complain when it tries to import the
> current directory as a module? I would expect an error, maybe:
> "ImportError: xxx is not a valid python module"

It doesen't try to import the current directory as a module. If first
looks *inside* the current directory for a module named abc (which can
be a directory named abc with a __init__.py file inside OR an abc.py
file OR an abc.pyc compiled file). So it finds abc, which is a dir but
also a *module* because of the __init__.py file, and imports it.

> If it is considered a valid python module and is executing it then who
> knows what it is doing.



-- 
Adeodato Simó (a.k.a. thibaut)
    EM: asp16 [ykwim] alu.ua.es | IM: my_dato [jabber.org] | PK: DA6AE621
 
Truth is the most valuable thing we have, so let's economize it.
                -- Mark Twain
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 204 bytes
Desc: Digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20031125/e341de78/attachment.sig>


More information about the Python-list mailing list