del an imported Class at EOF... why?

Terry Reedy tjreedy at udel.edu
Thu Oct 8 07:42:59 CEST 2009


Hans Mulder wrote:

> Errrhm, no.  He is not deleting the PyQt4 module from sys.modules;
> he's only deleting the name QtGui from his own namespace.  Next
> time Python comes across
> 
>     from PyQt4 import QtGui
> 
> , it finds that the module PyQt4 already exists in sys.modules, so
> Python does not have to load the module again.  All it has to do is
> bind name QtGui in the importing module to the class with the same
> name in the PyQt4 module.  That does not take many cycles.

I recently discovered that when IDLE restarts (as when one runs a file 
from an edit window), it clears the global namespace but does not clear 
sys.modules. Hence re-running a script that does time-consuming imports 
is much faster, as only the global name binding is done after the first run.




More information about the Python-list mailing list