Import without executing module

Lie Ryan lie.1296 at gmail.com
Tue Feb 10 08:03:41 EST 2009


On Tue, 03 Feb 2009 20:08:34 -0800, Stephen Hansen wrote:

> There is no need to try to make sure something is
> executed/compiled only once in Python like you may want to do in C.
> Every module is only ever compiled once: if you import it ten times in
> ten different places only the first will compile and execute the code,
> the rest of the calls will return that original module again.

<nitpick>
If you import a module, it will be recompiled only if the module changes 
from the precompiled .pyc/.pyo. OTOH, if you run a module, it will be 
recompiled every time even if there is no change.
</nitpick>




More information about the Python-list mailing list