load changes of subclasses

Bob Gailer bgailer at alum.rpi.edu
Tue Sep 23 14:14:55 EDT 2003


At 09:33 AM 9/23/2003, Gerrit Holl wrote:

>Tom wrote:
> > Date: Tue, 23 Sep 2003 16:56:55 +0200
> >
> > Hi,
> >
> > I have a main program  that uses a lot of definitions in different classes.
> > They are included like this:
> > from subclass1 import *
> > from subclass2 import *
>
>Note that 'subclass1' and 'subclass2' are not classes, but modules. A
>class is created with the 'class' statement:
>
>class MyClass:
>     def method(self):
>         return "Hi there!"
>
>A module is a file in the library.
>
> > My problem is: whenever I make changes in one of the classes I have to
> > close and reopen the main program for the changes to take effect. This
> > is kind of annoying, because I always want to test if my changes are
> > correct and that's why I have to run the main program. Is there some
> > kind of a shortcut where I don't have to close and reopen the main program?
>
>You can use the reload() function for that:
> >>> print reload.__doc__
>   reload(module) -> module
>
>   Reload the module.  The module must have been successfully imported before.

BUT realize that reloading does not rebind the names bound by the original 
from subclass1 import *. This is one reason to either avoid from import, or 
else:

try:del sys.modules['subclass1']
except:pass
from subclass1 import *

Bob Gailer
bgailer at alum.rpi.edu
303 442 2625
-------------- next part --------------

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003


More information about the Python-list mailing list