python -i (interactive environment)

Just just at xs4all.nl
Mon Mar 7 16:32:45 EST 2005


In article <mailman.42.1110224680.1799.python-list at python.org>,
 Steve Holden <steve at holdenweb.com> wrote:

> Michael Hoffman wrote:
> > Joe wrote:
> > 
> >> I want the script to decide whether to fall back to the interactive 
> >> prompt. You solution makes it ALWAYS fall back to the interactive prompt.
> > 
> > 
> > Actually, using sys.exit() means the program can exit even if python -i
> > is used.
> > 
> > You can use:
> > 
> > import code
> > code.interact()
> > 
> > which emulates the interactive prompt.
> 
> Unfortunately it does so in an entirely new namespace, thereby losing 
> the advantage of -i - namely, that you can investigate the program's 
> namespace after it's terminated.

code.interact() has a namespace argument ('local'), so it really easy to 
have it use the namespace you want.

Just



More information about the Python-list mailing list