Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > del an imported Class at EOF... why?

Reply
Thread Tools

del an imported Class at EOF... why?

 
 
Simon Forman
Guest
Posts: n/a
 
      10-08-2009
On Thu, Oct 8, 2009 at 1:42 AM, 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.


Is that with or without '-n'?
 
Reply With Quote
 
 
 
 
Terry Reedy
Guest
Posts: n/a
 
      10-08-2009
Simon Forman wrote:
> On Thu, Oct 8, 2009 at 1:42 AM, 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.

>
> 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.

 
Reply With Quote
 
 
 
 
Terry Reedy
Guest
Posts: n/a
 
      10-08-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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why do directly imported variables behave differently than thoseattached to imported module? Dun Peal Python 10 05-03-2011 10:11 PM
del class with recursive list duccio Python 3 03-10-2008 05:09 AM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
"Variable ... is not imported..." using an imported variable from a module Volker Nicolai Perl Misc 9 07-04-2005 08:34 AM
is it possible to del an imported module? dw Python 1 02-18-2004 05:30 PM



Advertisments