[Tutor] Resetting the environment

Magnus Lyckå magnus@thinkware.se
Tue Jun 3 06:55:02 2003


At 17:12 2003-06-02 -0700, Tom Plunket wrote:
>I'd basically like to undefine everything and unload all of the
>modules.

Why? In all my years with Python I never felt a need to do that.

The easiest thing is probably to restart the interpreter. There are
many things in python that you can't purge from memory, so if you
need to reclaim memory: restart the interpreter.

If your *real* problems is that the modules don't get reloaded
if you change them and do "import x" again, use "reload(x)" instead.

I suppose you could do something like:

for name in dir():
     del name

but that doesn't unload modules. It just makes them unavailable.
You need to do import followed by reload to get access to changed
modules.


--
Magnus Lycka (It's really Lyckå), magnus@thinkware.se
Thinkware AB, Sweden, www.thinkware.se
I code Python ~ The Agile Programming Language