del an imported Class at EOF... why?

Simon Forman sajmikins at gmail.com
Thu Oct 8 12:37:39 EDT 2009


On Thu, Oct 8, 2009 at 1:42 AM, Terry Reedy <tjreedy at udel.edu> 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.

Is that with or without '-n'?



More information about the Python-list mailing list