dynamic modules

Chris Barker chrishbarker at attbi.com
Wed Dec 19 14:37:52 EST 2001


Michael Hudson wrote:
> Fernando Pérez <fperez528 at yahoo.com> writes:
> > import plugin1 as p1
> >
> > ...
> >
> > del p1
> > In the next gc pass it should get picked up.
> 
> This won't work; consider sys.modules.

while you can't delete an entire module, can you delete some of it's
members? Example:

import plugin

# do stuff

del plugin.largedatastructure

If I did this, would the datastructure be deleted?

If so, it would acomplish most of what the OP wanted. The module would
still be there, but the large data structure wouldn't be. It also looks
like a reload() would bring back the data, although I'm not sure how
well that would work with a compiled module.

-Chris






-- 
Christopher Barker,
Ph.D.                                                           
ChrisHBarker at attbi.net                ---           ---           ---
                                     ---@@       -----@@       -----@@
                                   ------@@@     ------@@@     ------@@@
Oil Spill Modeling                ------   @    ------   @   ------   @
Water Resources Engineering       -------      ---------     --------    
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------



More information about the Python-list mailing list