is it possible to del an imported module?

Peter Hansen peter at
Wed Feb 18 18:30:56 CET 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.)


More information about the Python-list mailing list