del an imported Class at EOF... why?

Terry Reedy tjreedy at
Thu Oct 8 22:20:30 CEST 2009

Terry Reedy wrote:
> 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.

Whoops, on rechecking, above does not seem to be true. The faster rerun 
time I was seeing was due to some other cause. Sorry for the noise.

More information about the Python-list mailing list