Is this right? Multiple imports of same module.

Simon Brunning simon at brunningonline.net
Fri Mar 9 10:46:06 EST 2007


On 3/9/07, Lou Pecora <pecora at anvil.nrl.navy.mil> wrote:
>
> *In mod1.py
>
> import mymodule
>
> *In mod2.py
>
> import mymodule
>
> *In mod3.py
>
> import mymodule as MM
>
> Then mymodule is imported only once, but each module has access to it
> through the module name (mod1 and mod2) and the alias MM (mod3).  Is
> that right?

Yup, and occasionally it's useful to do stuff like this...

> I was concerned about multiple imports and efficiency.

... but not for this reason. Subsequent imports of an already loaded
module are very quick.

-- 
Cheers,
Simon B
simon at brunningonline.net
http://www.brunningonline.net/simon/blog/



More information about the Python-list mailing list