How do I undo an import??

Michael Hudson mwh21 at cam.ac.uk
Thu Apr 13 18:42:56 EDT 2000


"Tom" <tom-main at REMOVEME.home.com> writes:

> I'm a C++ programmer, new to Python, working with v1.5.2 on Windows.
> 
> I run the command-line interpreter, then I type:
> 
> >>> from NetCfg import *
> 
> to import my extension.  Now I want to unload my NetCfg DLL without exiting
> the interpreter.  How do I do this?

You don't, in general.

del sys.modules['NetCfg']

goes some of the way, but it's unlikely it goes far enough to let the
dll be unloaded from memory.
 
> Also, I type the above import command every time I start the interpreter.
> Is there some way to get have this command executed automatically?

Set the environment variable "PYTHONSTARTUP" to point to a file
containing commands you want executed.

At least, that's what I do on Linux.

Cheers,
M.

-- 
  ... but I guess there are some things that are so gross you just have
  to forget,  or it'll destroy something within you.  perl is the first
  such thing I have known.                 -- Erik Naggum, comp.lang.lisp



More information about the Python-list mailing list