Is this right? Multiple imports of same module.

Ben Finney bignose+hates-spam at benfinney.id.au
Sat Mar 10 01:16:35 CET 2007


Lou Pecora <pecora at anvil.nrl.navy.mil> writes:

> ['import mymodule' in three separate modules]
>
> 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?

Not quite. The module is imported three times, and is assigned to
three different namespaces; but the code in the module is executed
only once, the first time it is imported. Each subsequent import skips
the "execute the code" step.

-- 
 \       "My classmates would copulate with anything that moved, but I |
  `\            never saw any reason to limit myself."  -- Emo Philips |
_o__)                                                                  |
Ben Finney




More information about the Python-list mailing list