Imports awareness in Imported modules problem

Fredrik Lundh fredrik at pythonware.com
Sun Aug 24 08:59:55 CEST 2008


Mohamed Yousef wrote:

> why am i doing this in the first place
> I'm in the process of a medium project where imports of modules start
> to make a jungle and i wanted all needed imports to be in a single
> file (namely __init__.py)
> and then all imports are made once and other modules feel it

Python doesn't use a global namespace -- importing a given module into 
one module doesn't make it visible everywhere else (and trust me, this 
is a very good thing).

(it uses a global module cache, though, so it's only the first import 
that actually loads the module)

 > my goal is basically making W() aware of the re module when called
 > from A

to do that, add "import re" to the top of the C module.

see this page for a little more on Python's import mechanism:

     http://effbot.org/zone/import-confusion.htm

</F>




More information about the Python-list mailing list