is it possible to del an imported module?

Peter Hansen peter at engcorp.com
Wed Feb 18 12:30:56 EST 2004


dw wrote:
> 
> my program has potentially hundreds of small py file that
> each open an
> mdichildframe (just like demo from wxPython). I
> implemented it by
> importing the file before use, but would like it be get
> ridded off
> from memory afterward.

Files are actually imported only *once*, and the resulting module
is cached in sys.modules for later use.  If a second or third 
"import" statement imports the same module, it really just creates
a new reference to the same module.

If I were you, I wouldn't worry about the overhead of any of this
unless you actually observe excessive memory consumption in your
program.  (That is, if it doesn't actually cause trouble, just 
ignore it.)

-Peter



More information about the Python-list mailing list