Is this right? Multiple imports of same module.

Ben Finney bignose+hates-spam at benfinney.id.au
Fri Mar 9 19:16:35 EST 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