How to I restart an interactive session?

Mike Meyer mwm at mired.org
Fri Mar 18 17:07:10 EST 2005


"markscottwright" <markscottwright at gmail.com> writes:

> But, by deleting their namespace entries haven't I effectively unloaded
> them?  In other words, from the point of the interpreter, isn't the
> state at point A and point B the same?
>
>     --- point A:
>       import os
>       del __main__.__dict__['os']
>     --- point B

That depends on the module you import. At point B, sys.modules *will*
contain an entry for the imported module. That won't be true at point
A unless the module was a builtin one.

> I guess my question boils down to, is the state of the python
> interpreter kept anywhere other than the __main__ namespace?  Obviously
> the answer is yes - there's the current working directory and any
> running threads.  I think I'm willing to live with those (yeah, I know,
> those are the words of a man who is going to spend time chasing obscure
> side-effects...)

Yes. Various things in sys record information about the state of the
interpreter.

> But are there other things I'm missing?  Is my whole plan misguided
> from the beginning?

It's not clear that misguided is the correct term. You're trying to do
something with the interpreter that it wasn't designed for. I'd say
that was unwise. Whether or not it *should* have been designed for
what you want to do is another problem.

     <mike
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list