del an imported Class at EOF... why?

Terry Reedy tjreedy at udel.edu
Thu Oct 8 16:13:17 EDT 2009


Simon Forman wrote:
> 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'?

The Windows start menu IDLE entry, which I gather is without -n, though 
the property sheet does not actually give the command-line equivalent.




More information about the Python-list mailing list